diff options
| author | Zog | 2018-03-07 07:50:02 +0100 | 
|---|---|---|
| committer | Zog | 2018-03-12 12:00:13 +0100 | 
| commit | b810deb08cadd56caeb76eb81cff363458bb79a3 (patch) | |
| tree | 6fd0c1bc383a9fa501666f6d86cee2ec06c573cd /spec | |
| parent | 7b53b4c86d0469c21b54f4f974fbae5fc205ed0f (diff) | |
| download | chouette-core-b810deb08cadd56caeb76eb81cff363458bb79a3.tar.bz2 | |
Refs #6133; Fix specs
Diffstat (limited to 'spec')
20 files changed, 109 insertions, 150 deletions
| diff --git a/spec/controllers/api/v1/imports_controller_spec.rb b/spec/controllers/api/v1/imports_controller_spec.rb index 8077dd052..f7022115a 100644 --- a/spec/controllers/api/v1/imports_controller_spec.rb +++ b/spec/controllers/api/v1/imports_controller_spec.rb @@ -30,7 +30,7 @@ RSpec.describe Api::V1::ImportsController, type: :controller do        it 'should be successful' do          expect {            post :create, workbench_id: workbench.id, workbench_import: {name: "test", file: file, creator: 'test'}, format: :json -        }.to change{WorkbenchImport.count}.by(1) +        }.to change{Import::Workbench.count}.by(1)          expect(response).to be_success        end      end diff --git a/spec/controllers/vehicle_journey_imports_controller_spec.rb b/spec/controllers/vehicle_journey_imports_controller_spec.rb deleted file mode 100644 index 633f90b70..000000000 --- a/spec/controllers/vehicle_journey_imports_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe ImportTasksController, :type => :controller do -  login_user -end diff --git a/spec/factories/import_messages.rb b/spec/factories/imports/import_messages.rb index 5d936679a..f5edf1685 100644 --- a/spec/factories/import_messages.rb +++ b/spec/factories/imports/import_messages.rb @@ -1,5 +1,5 @@  FactoryGirl.define do -  factory :import_message do +  factory :import_message, class: Import::Message do      association :import      association :resource, factory: :import_resource      criticity :info diff --git a/spec/factories/import_resources.rb b/spec/factories/imports/import_resources.rb index 76afcc486..aaf7e3111 100644 --- a/spec/factories/import_resources.rb +++ b/spec/factories/imports/import_resources.rb @@ -1,5 +1,5 @@  FactoryGirl.define do -  factory :import_resource do +  factory :import_resource, class: Import::Resource do      association :import      status :WARNING      sequence(:name) { |n| "Import resource #{n}" } diff --git a/spec/factories/imports.rb b/spec/factories/imports/imports.rb index e07447b60..cb7764cc6 100644 --- a/spec/factories/imports.rb +++ b/spec/factories/imports/imports.rb @@ -1,5 +1,5 @@  FactoryGirl.define do -  factory :import do +  factory :import, class: Import::Base do      sequence(:name) { |n| "Import #{n}" }      current_step_id "MyString"      current_step_progress 1.5 @@ -16,7 +16,7 @@ FactoryGirl.define do      end    end -  factory :bad_import do +  factory :bad_import, class: Import::Base do      sequence(:name) { |n| "Import #{n}" }      current_step_id "MyString"      current_step_progress 1.5 diff --git a/spec/factories/netex_imports.rb b/spec/factories/imports/netex_imports.rb index b59267a0a..7ee6839e8 100644 --- a/spec/factories/netex_imports.rb +++ b/spec/factories/imports/netex_imports.rb @@ -1,7 +1,7 @@  FactoryGirl.define do -  factory :netex_import, class: NetexImport, parent: :import do +  factory :netex_import, class: Import::Netex, parent: :import do      file { File.open(Rails.root.join('spec', 'fixtures', 'OFFRE_TRANSDEV_2017030112251.zip')) }      association :parent, factory: :workbench_import -     +    end  end diff --git a/spec/factories/workbench_imports.rb b/spec/factories/imports/workbench_imports.rb index 466bfe688..5ed1ee4e5 100644 --- a/spec/factories/workbench_imports.rb +++ b/spec/factories/imports/workbench_imports.rb @@ -1,5 +1,5 @@  FactoryGirl.define do -  factory :workbench_import, class: WorkbenchImport, parent: :import do +  factory :workbench_import, class: Import::Workbench, parent: :import do      file { File.open(Rails.root.join('spec', 'fixtures', 'OFFRE_TRANSDEV_2017030112251.zip')) }    end  end diff --git a/spec/models/export_log_message_spec.rb b/spec/models/export_log_message_spec.rb deleted file mode 100644 index 5ab32dec0..000000000 --- a/spec/models/export_log_message_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'spec_helper' - -describe ExportLogMessage, :type => :model do - -  # describe "#attributes" do - -  #   subject { create :export_log_message } - -  #   it "should read json stored in database" do -  #     subject.update_attribute :arguments, { "key" => "value"} -  #     expect(subject.raw_attributes).to eq({ "key" => "value"}.to_json) -  #   end - -  # end - -end diff --git a/spec/models/gtfs_export_spec.rb b/spec/models/gtfs_export_spec.rb index ccc98e872..0ef3660f5 100644 --- a/spec/models/gtfs_export_spec.rb +++ b/spec/models/gtfs_export_spec.rb @@ -1,33 +1,33 @@  require 'spec_helper' -describe GtfsExport, :type => :model do - -  describe "#time_zone" do - -    context "when exported data are not StopAreas" do - -      before do -        subject.references_type = "network" -      end - -      it "should be mandatory" do -        should validate_presence_of(:time_zone) -      end - -    end - -    context "when export data are StopArea" do - -      before do -        subject.references_type = "stop_area" -      end - -      it "should be mandatory" do -        should_not validate_presence_of(:time_zone) -      end - -    end - -  end - -end +# describe GtfsExport, :type => :model do +# +#   describe "#time_zone" do +# +#     context "when exported data are not StopAreas" do +# +#       before do +#         subject.references_type = "network" +#       end +# +#       it "should be mandatory" do +#         should validate_presence_of(:time_zone) +#       end +# +#     end +# +#     context "when export data are StopArea" do +# +#       before do +#         subject.references_type = "stop_area" +#       end +# +#       it "should be mandatory" do +#         should_not validate_presence_of(:time_zone) +#       end +# +#     end +# +#   end +# +# end diff --git a/spec/models/gtfs_import_spec.rb b/spec/models/gtfs_import_spec.rb index 07cc1905d..5cb69332c 100644 --- a/spec/models/gtfs_import_spec.rb +++ b/spec/models/gtfs_import_spec.rb @@ -1,6 +1,6 @@  require 'spec_helper' -describe GtfsImport, :type => :model do +describe Import::Gtfs, :type => :model do   # describe "#object_id_prefix" do diff --git a/spec/models/import/netex_import_spec.rb b/spec/models/import/netex_import_spec.rb index 8ffeed1f4..9b9f50117 100644 --- a/spec/models/import/netex_import_spec.rb +++ b/spec/models/import/netex_import_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe NetexImport, type: [:model, :with_commit] do +RSpec.describe Import::Netex, type: [:model, :with_commit] do    let( :boiv_iev_uri ){  URI("#{Rails.configuration.iev_url}/boiv_iev/referentials/importer/new?id=#{subject.id}")} @@ -30,4 +30,42 @@ RSpec.describe NetexImport, type: [:model, :with_commit] do      end    end +  describe "#destroy" do +    it "must destroy its associated Referential if ready: false" do +      workbench_import = create(:workbench_import) +      referential_ready_false = create(:referential, ready: false) +      referential_ready_true = create(:referential, ready: true) +      create( +        :netex_import, +        parent: workbench_import, +        referential: referential_ready_false +      ) +      create( +        :netex_import, +        parent: workbench_import, +        referential: referential_ready_true +      ) + +      workbench_import.destroy + +      expect( +        Referential.where(id: referential_ready_false.id).exists? +      ).to be false +      expect( +        Referential.where(id: referential_ready_true.id).exists? +      ).to be true +    end + +    it "doesn't try to destroy nil referentials" do +      workbench_import = create(:workbench_import) +      create( +        :netex_import, +        parent: workbench_import, +        referential: nil +      ) + +      expect { workbench_import.destroy }.not_to raise_error +    end +  end +  end diff --git a/spec/models/import_message_spec.rb b/spec/models/import_message_spec.rb index 2d8aac2b7..48e03a2cc 100644 --- a/spec/models/import_message_spec.rb +++ b/spec/models/import_message_spec.rb @@ -1,6 +1,6 @@  require 'rails_helper' -RSpec.describe ImportMessage, :type => :model do +RSpec.describe Import::Message, :type => :model do    it { should validate_presence_of(:criticity) }    it { should belong_to(:import) }    it { should belong_to(:resource) } diff --git a/spec/models/import_resource_spec.rb b/spec/models/import_resource_spec.rb index c88bb5dd2..7d2eab8f1 100644 --- a/spec/models/import_resource_spec.rb +++ b/spec/models/import_resource_spec.rb @@ -1,6 +1,6 @@  require 'rails_helper' -RSpec.describe ImportResource, :type => :model do +RSpec.describe Import::Resource, :type => :model do    it { should belong_to(:import) }    it { should enumerize(:status).in("OK", "ERROR", "WARNING", "IGNORED") } diff --git a/spec/models/import_service_spec.rb b/spec/models/import_service_spec.rb deleted file mode 100644 index e7ee062d6..000000000 --- a/spec/models/import_service_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' - -describe ImportService, :type => :model do - -  let(:referential) { create(:referential, :slug => "test") } -   -  subject { ImportService.new(referential) } - -  describe '.find' do -     -    it "should build an import with a scheduled job" do       -    end - -    it "should build an import with a terminated job" do -    end -     -  end -   -end diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 8b85f151b..cbc5907fa 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Import, type: :model do +RSpec.describe Import::Base, type: :model do    it { should belong_to(:referential) }    it { should belong_to(:workbench) } @@ -39,7 +39,7 @@ RSpec.describe Import, type: :model do          )          current_import = create(:workbench_import, status: 'pending') -        Import.abort_old +        Import::Base.abort_old          expect(current_import.reload.status).to eq('pending')          expect(old_import.reload.status).to eq('aborted') @@ -54,7 +54,7 @@ RSpec.describe Import, type: :model do            created_at: 4.hours.ago - 1.minute          ) -        Import.abort_old +        Import::Base.abort_old          expect(import.reload.status).to eq('successful')        end @@ -73,7 +73,7 @@ RSpec.describe Import, type: :model do            created_at: 4.hours.ago - 1.minute          ) -        NetexImport.abort_old +        Import::Netex.abort_old          expect(workbench_import.reload.status).to eq('pending')          expect(netex_import.reload.status).to eq('aborted') @@ -88,25 +88,25 @@ RSpec.describe Import, type: :model do        netex_import.parent.destroy        expect(netex_import.parent).to be_destroyed -      expect(NetexImport.count).to eq(0) +      expect(Import::Netex.count).to eq(0)      end -    it "must destroy all associated ImportMessages" do +    it "must destroy all associated Import::Messages" do        import = create(:import)        create(:import_resource, import: import)        import.destroy -      expect(ImportResource.count).to eq(0) +      expect(Import::Resource.count).to eq(0)      end -    it "must destroy all associated ImportResources" do +    it "must destroy all associated Import::Resources" do        import = create(:import)        create(:import_message, import: import)        import.destroy -      expect(ImportMessage.count).to eq(0) +      expect(Import::Message.count).to eq(0)      end    end diff --git a/spec/models/netex_export_spec.rb b/spec/models/netex_export_spec.rb index 1d09fa07f..345bf4d5a 100644 --- a/spec/models/netex_export_spec.rb +++ b/spec/models/netex_export_spec.rb @@ -1,10 +1,10 @@  require 'spec_helper' -describe NetexExport, :type => :model do - -  # describe '#export_options' do -  #   subject { super().export_options } -  #   it { is_expected.to include(:format => :netex) } -  # end -   -end +# describe NetexExport, :type => :model do +# +#   # describe '#export_options' do +#   #   subject { super().export_options } +#   #   it { is_expected.to include(:format => :netex) } +#   # end +# +# end diff --git a/spec/models/netex_import_spec.rb b/spec/models/netex_import_spec.rb deleted file mode 100644 index c6051a869..000000000 --- a/spec/models/netex_import_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -RSpec.describe NetexImport, type: :model do -  describe "#destroy" do -    it "must destroy its associated Referential if ready: false" do -      workbench_import = create(:workbench_import) -      referential_ready_false = create(:referential, ready: false) -      referential_ready_true = create(:referential, ready: true) -      create( -        :netex_import, -        parent: workbench_import, -        referential: referential_ready_false -      ) -      create( -        :netex_import, -        parent: workbench_import, -        referential: referential_ready_true -      ) - -      workbench_import.destroy - -      expect( -        Referential.where(id: referential_ready_false.id).exists? -      ).to be false -      expect( -        Referential.where(id: referential_ready_true.id).exists? -      ).to be true -    end - -    it "doesn't try to destroy nil referentials" do -      workbench_import = create(:workbench_import) -      create( -        :netex_import, -        parent: workbench_import, -        referential: nil -      ) - -      expect { workbench_import.destroy }.not_to raise_error -    end -  end -end diff --git a/spec/policies/import_policy_spec.rb b/spec/policies/import_policy_spec.rb index 9c7fca8a5..f9effd21a 100644 --- a/spec/policies/import_policy_spec.rb +++ b/spec/policies/import_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe ImportPolicy, type: :policy do +RSpec.describe Import::BasePolicy, type: :policy do    let( :record ){ build_stubbed :import }    before { stub_policy_scope(record) } diff --git a/spec/requests/api/v1/netex_import_spec.rb b/spec/requests/api/v1/netex_import_spec.rb index 8597c1d32..14dac9a25 100644 --- a/spec/requests/api/v1/netex_import_spec.rb +++ b/spec/requests/api/v1/netex_import_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe "NetexImport", type: :request do +RSpec.describe "Import::Netex", type: :request do    describe 'POST netex_imports' do @@ -39,7 +39,7 @@ RSpec.describe "NetexImport", type: :request do          post_request.(netex_import: legal_attributes)          expect( response ).to be_success          expect( json_response_body ).to eq( -          'id'             => NetexImport.last.id, +          'id'             => Import::Netex.last.id,            'referential_id' => Referential.last.id,            'workbench_id'   => workbench.id          ) @@ -51,7 +51,7 @@ RSpec.describe "NetexImport", type: :request do          create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00108', line_referential: workbench.line_referential)          create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00109', line_referential: workbench.line_referential) -        expect{ post_request.(netex_import: legal_attributes) }.to change{NetexImport.count}.by(1) +        expect{ post_request.(netex_import: legal_attributes) }.to change{Import::Netex.count}.by(1)        end        it 'creates a correct Referential', pending: 'see #5073' do @@ -96,7 +96,7 @@ RSpec.describe "NetexImport", type: :request do            end            it 'does not create an Import object' do -            expect{ post_request.(netex_import: illegal_attributes) }.not_to change{Import.count} +            expect{ post_request.(netex_import: illegal_attributes) }.not_to change{Import::Base.count}            end            it 'might not create a referential' do diff --git a/spec/services/parent_notifier_spec.rb b/spec/services/parent_notifier_spec.rb index ecf508fcd..d4ca73ab3 100644 --- a/spec/services/parent_notifier_spec.rb +++ b/spec/services/parent_notifier_spec.rb @@ -20,7 +20,7 @@ RSpec.describe ParentNotifier do          expect(netex_import).to receive(:notify_parent)        end -      ParentNotifier.new(Import).notify_when_finished(netex_imports) +      ParentNotifier.new(Import::Base).notify_when_finished(netex_imports)      end      it "doesn't call #notify_parent if its `notified_parent_at` is set" do @@ -33,7 +33,7 @@ RSpec.describe ParentNotifier do        expect(netex_import).not_to receive(:notify_parent) -      ParentNotifier.new(Import).notify_when_finished +      ParentNotifier.new(Import::Base).notify_when_finished      end    end @@ -47,7 +47,7 @@ RSpec.describe ParentNotifier do        )        expect( -        ParentNotifier.new(Import).objects_pending_notification +        ParentNotifier.new(Import::Base).objects_pending_notification        ).to eq([netex_import])      end @@ -55,7 +55,7 @@ RSpec.describe ParentNotifier do        create(:import, parent: nil)        expect( -        ParentNotifier.new(Import).objects_pending_notification +        ParentNotifier.new(Import::Base).objects_pending_notification        ).to be_empty      end @@ -70,7 +70,7 @@ RSpec.describe ParentNotifier do        end        expect( -        ParentNotifier.new(Import).objects_pending_notification +        ParentNotifier.new(Import::Base).objects_pending_notification        ).to be_empty      end @@ -83,7 +83,7 @@ RSpec.describe ParentNotifier do        )        expect( -        ParentNotifier.new(Import).objects_pending_notification +        ParentNotifier.new(Import::Base).objects_pending_notification        ).to be_empty      end    end | 
