combination_steps.rb revision 2139291198cf7b0232b6628c89e40f985a4332c0
2058N/AGiven(/^that I have a valid API\-Key$/) do
2058N/A @api_key = FactoryGirl.create :api_key
2058N/A @user = @api_key.user
2058N/Aend
2058N/A
2058N/AGiven(/^that I have an invalid API\-Key$/) do
2058N/A @api_key = FactoryGirl.create :api_key, :invalid
2058N/A @user = @api_key.user
2058N/Aend
2058N/A
2058N/AGiven(/^I have a repository with path: "([^"]+)"$/) do |path|
2058N/A permission =
2058N/A if @user
2058N/A FactoryGirl.create :permission, subject: @user
2058N/A else
2058N/A FactoryGirl.create :permission
2058N/A end
2058N/A @repository = permission.item
2058N/A @repository.path = path
2058N/A @repository.save!
6033N/Aend
2058N/A
2058N/AGiven(/^I know of a repository with path: "([^"]+)"$/) do |path|
2058N/A @repository = FactoryGirl.create :repository, path: path
2058N/Aend
6033N/A
2058N/AGiven(/^I have (\d+) ontologies$/) do |number|
2058N/A @ontologies = (1..number.to_i).to_a.
2058N/A map { FactoryGirl.create :ontology }
6033N/Aend
2058N/A
6033N/AWhen(/^I create a combination via the API of these ontologies$/) do
3769N/A header 'Accept', 'application/json'
2058N/A header 'Content-Type', 'application/json'
6033N/A header Api::V1::Base::API_KEY_HEADER, @api_key.try(:key)
3661N/A request "/#{@repository.path}///combinations",\
3778N/A method: :post,
3778N/A input: {
3778N/A nodes: @ontologies.map { |o| locid_for(o) }
3996N/A }.to_json
3996N/Aend
3996N/A
2058N/AWhen(/^I create a combination via the API with these:$/) do |table|
2058N/A header 'Accept', 'application/json'
2058N/A header 'Content-Type', 'application/json'
2058N/A header Api::V1::Base::API_KEY_HEADER, @api_key.try(:key)
2058N/A request "/#{@repository.path}///combinations",\
2058N/A method: :post,
2058N/A input: table.hashes.first.to_json
2058N/Aend
2058N/A
2058N/AThen(/^I should get a (\d+) response$/) do |number|
2058N/A expect(last_response.status).to eq(number.to_i)
2058N/Aend
2058N/A
2058N/AThen(/^a location\-header to the combination\-ontology$/) do
2058N/A expect(last_response.headers["Location"]).to eq(Ontology.last.locid)
2058N/Aend
2058N/A
2058N/AThen(/^a location\-header to an action$/) do
2058N/A expect(last_response.headers["Location"]).
2058N/A to eq(action_iri_path(Action.last))
2058N/Aend
3996N/A
3996N/AThen(/^the body should be valid for a (\d+) combination-response/) do |status|
3996N/A schema = schema_for("repository/combinations/POST/response/#{status}")
3996N/A VCR.use_cassette "api/json-schemata/repository/combinations/#{status}" do
4070N/A expect(last_response.body).to match_json_schema(schema)
4070N/A end
3996N/Aend
3996N/A