diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/decorators/referential_decorator_spec.rb | 5 | ||||
| -rw-r--r-- | spec/factories/imports.rb | 4 | ||||
| -rw-r--r-- | spec/models/api/v1/api_key_spec.rb | 2 | ||||
| -rw-r--r-- | spec/models/import_spec.rb | 1 | ||||
| -rw-r--r-- | spec/policies/referential_policy_spec.rb | 2 | ||||
| -rw-r--r-- | spec/requests/api/v1/netex_import_spec.rb | 72 | ||||
| -rw-r--r-- | spec/routing/api/v1/access_links_routes_spec.rb | 9 | ||||
| -rw-r--r-- | spec/routing/group_of_lines_spec.rb | 4 |
8 files changed, 89 insertions, 10 deletions
diff --git a/spec/decorators/referential_decorator_spec.rb b/spec/decorators/referential_decorator_spec.rb index 5de6b7e95..16da8d30b 100644 --- a/spec/decorators/referential_decorator_spec.rb +++ b/spec/decorators/referential_decorator_spec.rb @@ -25,7 +25,7 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do end end - context 'all rights and different organisation' do + context 'all rights and different organisation' do let( :user ){ build_stubbed :allmighty_user } @@ -33,10 +33,11 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do expect_action_link_elements.to be_empty expect_action_link_hrefs.to eq([ referential_time_tables_path(object), + new_referential_path(from: object), ]) end end - context 'all rights and same organisation' do + context 'all rights and same organisation' do let( :user ){ build_stubbed :allmighty_user, organisation: referential.organisation } diff --git a/spec/factories/imports.rb b/spec/factories/imports.rb index 6db4b6b5f..e19fe92bb 100644 --- a/spec/factories/imports.rb +++ b/spec/factories/imports.rb @@ -10,8 +10,8 @@ FactoryGirl.define do started_at nil ended_at nil - factory :workbench_import do - type 'WorkbenchImport' + factory :netex_import, class: NetexImport do + file {File.open(Rails.root.join('spec', 'fixtures', 'terminated_job.json'))} end end end diff --git a/spec/models/api/v1/api_key_spec.rb b/spec/models/api/v1/api_key_spec.rb index eb8826c0e..8a34c9221 100644 --- a/spec/models/api/v1/api_key_spec.rb +++ b/spec/models/api/v1/api_key_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe Api::V1::ApiKey, :type => :model do let!(:referential){create(:referential)} subject { Api::V1::ApiKey.create( :name => "test", :referential => referential)} diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index a2855d086..34bfb0b23 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -3,6 +3,7 @@ require 'rails_helper' RSpec.describe Import, :type => :model do it { should belong_to(:referential) } it { should belong_to(:workbench) } + it { should belong_to(:parent).class_name(described_class.to_s) } it { should enumerize(:status).in(:new, :pending, :successful, :failed, :canceled, :running, :aborted ) } diff --git a/spec/policies/referential_policy_spec.rb b/spec/policies/referential_policy_spec.rb index 33d8e13e8..69d0eb17b 100644 --- a/spec/policies/referential_policy_spec.rb +++ b/spec/policies/referential_policy_spec.rb @@ -46,7 +46,7 @@ RSpec.describe ReferentialPolicy, type: :policy do # ------------------ permissions :clone? do - it_behaves_like 'permitted policy and same organisation', 'referentials.create', archived: true + it_behaves_like 'permitted policy', 'referentials.create', archived: true end permissions :archive? do diff --git a/spec/requests/api/v1/netex_import_spec.rb b/spec/requests/api/v1/netex_import_spec.rb new file mode 100644 index 000000000..9fbf8f801 --- /dev/null +++ b/spec/requests/api/v1/netex_import_spec.rb @@ -0,0 +1,72 @@ +RSpec.describe "NetexImport", type: :request do + + describe 'POST netex_imports' do + + let( :referential ){ create :referential } + + let( :file_path ){'spec/fixtures/neptune.zip'} + let( :file ){ fixture_file_upload( file_path ) } + + let( :post_request ) do + -> (attributes) do + post "/api/v1/netex_imports.json", + attributes, + authorization + end + end + + let( :legal_attributes ) do + { + name: 'hello world', + file: file, + referential_id: referential.id + } + end + + let( :illegal_attributes ) do + { referential_id: referential.id } + end + + context 'with correct credentials and correct request' do + let( :authorization ){ authorization_token_header( get_api_key.token ) } + + + it 'succeeds' do + post_request.(netex_import: legal_attributes) + expect( response ).to be_success + expect( json_response_body ).to eq({'id' => NetexImport.last.id, 'type' => 'NetexImport'}) + end + + it 'creates a NetexImport object in the DB' do + expect{ post_request.(netex_import: legal_attributes) }.to change{NetexImport.count}.by(1) + end + end + + context 'with incorrect credentials and correct request' do + let( :authorization ){ authorization_token_header( "#{referential.id}-incorrect_token") } + + it 'does not succeed' do + post_request.(netex_import: legal_attributes) + expect( response.status ).to eq(401) + end + + it 'does not create an Import object' do + expect{ post_request.(netex_import: legal_attributes) }.not_to change{Import.count} + end + end + + context 'with correct credentials and incorrect request' do + let( :authorization ){ authorization_token_header( get_api_key.token ) } + + it 'does not succeed' do + post_request.(netex_import: illegal_attributes) + expect( response.status ).to eq(406) + expect( json_response_body['errors']['file'] ).not_to be_empty + end + + it 'does not create an Import object' do + expect{ post_request.(netex_import: illegal_attributes) }.not_to change{Import.count} + end + end + end +end diff --git a/spec/routing/api/v1/access_links_routes_spec.rb b/spec/routing/api/v1/access_links_routes_spec.rb new file mode 100644 index 000000000..9164d3f05 --- /dev/null +++ b/spec/routing/api/v1/access_links_routes_spec.rb @@ -0,0 +1,9 @@ +RSpec.describe Api::V1::AccessLinksController, type: :controller do + + it 'routes to index' do + expect( get: '/api/v1/access_links' ).to route_to( + controller: 'api/v1/access_links', + action: 'index' + ) + end +end diff --git a/spec/routing/group_of_lines_spec.rb b/spec/routing/group_of_lines_spec.rb index 2a7262893..01ebeefe4 100644 --- a/spec/routing/group_of_lines_spec.rb +++ b/spec/routing/group_of_lines_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe GroupOfLinesController do +RSpec.describe GroupOfLinesController do describe "routing" do it "not recognize #routes" do expect(get( "/line_referentials/1/group_of_lines/2/routes")).not_to route_to( |
