diff options
| author | Zog | 2018-03-09 17:25:38 +0100 | 
|---|---|---|
| committer | Zog | 2018-03-12 12:00:15 +0100 | 
| commit | 3a738f4509a67d5024fb85bb551c7ec285cd031e (patch) | |
| tree | 3fd3f0cbfb133e07c66cd3795e81cdd74c648397 /spec | |
| parent | 0cd50ea684248e13391ef4f5ee5af5550ff6491f (diff) | |
| download | chouette-core-3a738f4509a67d5024fb85bb551c7ec285cd031e.tar.bz2 | |
Refs #6133; Fix specs
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/controllers/exports_controller_spec.rb | 10 | ||||
| -rw-r--r-- | spec/factories/exports/export_resources.rb | 4 | ||||
| -rw-r--r-- | spec/models/export/export_spec.rb | 86 | ||||
| -rw-r--r-- | spec/models/export/workbench_export_spec.rb | 10 | ||||
| -rw-r--r-- | spec/models/export/workgroup_export_spec.rb | 10 | ||||
| -rw-r--r-- | spec/models/import/import_spec.rb | 15 | ||||
| -rw-r--r-- | spec/models/simple_exporter_spec.rb | 10 | ||||
| -rw-r--r-- | spec/models/simple_importer_spec.rb | 8 | ||||
| -rw-r--r-- | spec/services/parent_notifier_spec.rb | 2 | 
9 files changed, 79 insertions, 76 deletions
| diff --git a/spec/controllers/exports_controller_spec.rb b/spec/controllers/exports_controller_spec.rb index dbc8b3f35..3a67497ec 100644 --- a/spec/controllers/exports_controller_spec.rb +++ b/spec/controllers/exports_controller_spec.rb @@ -27,7 +27,9 @@ RSpec.describe ExportsController, :type => :controller do      context "with full params" do        let(:params){{          name: "foo", -        type: "Export::Netex" +        type: "Export::Netex", +        duration: 12, +        export_type: :line        }}        it 'should be successful' do @@ -45,7 +47,7 @@ RSpec.describe ExportsController, :type => :controller do      context "with missing options" do        let(:params){{          name: "foo", -        type: "Export::Workbench" +        type: "Export::Workgroup"        }}        it 'should be unsuccessful' do @@ -56,8 +58,8 @@ RSpec.describe ExportsController, :type => :controller do      context "with all options" do        let(:params){{          name: "foo", -        type: "Export::Workbench", -        timelapse: 90 +        type: "Export::Workgroup", +        duration: 90        }}        it 'should be successful' do diff --git a/spec/factories/exports/export_resources.rb b/spec/factories/exports/export_resources.rb index e09787b52..8e38235cd 100644 --- a/spec/factories/exports/export_resources.rb +++ b/spec/factories/exports/export_resources.rb @@ -1,8 +1,8 @@  FactoryGirl.define do    factory :export_resource, class: Export::Resource do -    association :export -    status :WARNING      sequence(:name) { |n| "Export resource #{n}" } +    association :export, factory: :netex_export +    status :WARNING      resource_type 'type'      reference 'reference'    end diff --git a/spec/models/export/export_spec.rb b/spec/models/export/export_spec.rb index 089f4a2b7..ca94c1ff1 100644 --- a/spec/models/export/export_spec.rb +++ b/spec/models/export/export_spec.rb @@ -11,19 +11,19 @@ RSpec.describe Export::Base, type: :model do    include ActionDispatch::TestProcess    it { should allow_value(fixture_file_upload('OFFRE_TRANSDEV_2017030112251.zip')).for(:file) } -  it { should_not allow_value(fixture_file_upload('users.json')).for(:file).with_message(I18n.t('errors.messages.extension_whitelist_error', extension: '"json"', allowed_types: "zip")) } +  it { should_not allow_value(fixture_file_upload('reflex_updated.xml')).for(:file).with_message(I18n.t('errors.messages.extension_whitelist_error', extension: '"xml"', allowed_types: "zip, csv, json")) } -  let(:workbench_export) {netex_export.parent} -  let(:workbench_export_with_completed_steps) do +  let(:workgroup_export) {netex_export.parent} +  let(:workgroup_export_with_completed_steps) do      build_stubbed( -      :workbench_export, +      :workgroup_export,        total_steps: 2,        current_step: 2      )    end    let(:netex_export) do -    build_stubbed( +    create(        :netex_export      )    end @@ -32,11 +32,11 @@ RSpec.describe Export::Base, type: :model do      it "changes exports older than 4 hours to aborted" do        Timecop.freeze(Time.now) do          old_export = create( -          :workbench_export, +          :workgroup_export,            status: 'pending',            created_at: 4.hours.ago - 1.minute          ) -        current_export = create(:workbench_export, status: 'pending') +        current_export = create(:workgroup_export, status: 'pending')          Export::Base.abort_old @@ -48,7 +48,7 @@ RSpec.describe Export::Base, type: :model do      it "doesn't work on exports with a `finished_status`" do        Timecop.freeze(Time.now) do          export = create( -          :workbench_export, +          :workgroup_export,            status: 'successful',            created_at: 4.hours.ago - 1.minute          ) @@ -61,8 +61,8 @@ RSpec.describe Export::Base, type: :model do      it "only works on the caller type" do        Timecop.freeze(Time.now) do -        workbench_export = create( -          :workbench_export, +        workgroup_export = create( +          :workgroup_export,            status: 'pending',            created_at: 4.hours.ago - 1.minute          ) @@ -74,7 +74,7 @@ RSpec.describe Export::Base, type: :model do          Export::Netex.abort_old -        expect(workbench_export.reload.status).to eq('pending') +        expect(workgroup_export.reload.status).to eq('pending')          expect(netex_export.reload.status).to eq('aborted')        end      end @@ -91,7 +91,7 @@ RSpec.describe Export::Base, type: :model do      end      it "must destroy all associated Export::Messages" do -      export = create(:export) +      export = create(:netex_export)        create(:export_resource, export: export)        export.destroy @@ -100,7 +100,7 @@ RSpec.describe Export::Base, type: :model do      end      it "must destroy all associated Export::Resources" do -      export = create(:export) +      export = create(:netex_export)        create(:export_message, export: export)        export.destroy @@ -113,30 +113,30 @@ RSpec.describe Export::Base, type: :model do      it "must call #child_change on its parent" do        allow(netex_export).to receive(:update) -      expect(workbench_export).to receive(:child_change) - +      expect(workgroup_export).to receive(:child_change) +      netex_export.status = :foo        netex_export.notify_parent      end      it "must update the :notified_parent_at field of the child export" do -      allow(workbench_export).to receive(:child_change) +      allow(workgroup_export).to receive(:child_change) -      Timecop.freeze(DateTime.now) do -        expect(netex_export).to receive(:update).with( -          notified_parent_at: DateTime.now -        ) +      Timecop.freeze(Time.now) do +        netex_export.status = :bar          netex_export.notify_parent +        expect(netex_export.notified_parent_at).to eq Time.now +        expect(netex_export.reload.notified_parent_at).to eq Time.now        end      end    end    describe "#child_change" do      it "calls #update_status" do -      allow(workbench_export).to receive(:update) +      allow(workgroup_export).to receive(:update) -      expect(workbench_export).to receive(:update_status) -      workbench_export.child_change +      expect(workgroup_export).to receive(:update_status) +      workgroup_export.child_change      end    end @@ -145,16 +145,16 @@ RSpec.describe Export::Base, type: :model do        "updates :status to failed when >=1 child has failing status"      ) do |failure_status|        it "updates :status to failed when >=1 child has failing status" do -        workbench_export = create(:workbench_export) +        workgroup_export = create(:workgroup_export)          create(            :netex_export, -          parent: workbench_export, +          parent: workgroup_export,            status: failure_status          ) -        workbench_export.update_status +        workgroup_export.update_status -        expect(workbench_export.status).to eq('failed') +        expect(workgroup_export.status).to eq('failed')        end      end @@ -172,67 +172,67 @@ RSpec.describe Export::Base, type: :model do      )      it "updates :status to successful when all children are successful" do -      workbench_export = create(:workbench_export) +      workgroup_export = create(:workgroup_export)        exports = create_list(          :netex_export,          2, -        parent: workbench_export, +        parent: workgroup_export,          status: 'successful'        ) -      workbench_export.update_status +      workgroup_export.update_status -      expect(workbench_export.status).to eq('successful') +      expect(workgroup_export.status).to eq('successful')      end      it "updates :status to failed when any child has failed" do -      workbench_export = create(:workbench_export) +      workgroup_export = create(:workgroup_export)        [          'failed',          'successful'        ].each do |status|          create(            :netex_export, -          parent: workbench_export, +          parent: workgroup_export,            status: status          )        end -      workbench_export.update_status +      workgroup_export.update_status -      expect(workbench_export.status).to eq('failed') +      expect(workgroup_export.status).to eq('failed')      end      it "updates :status to warning when any child has warning or successful" do -      workbench_export = create(:workbench_export) +      workgroup_export = create(:workgroup_export)        [          'warning',          'successful'        ].each do |status|          create(            :netex_export, -          parent: workbench_export, +          parent: workgroup_export,            status: status          )        end -      workbench_export.update_status +      workgroup_export.update_status -      expect(workbench_export.status).to eq('warning') +      expect(workgroup_export.status).to eq('warning')      end      it "updates :ended_at to now when status is finished" do -      workbench_export = create(:workbench_export) +      workgroup_export = create(:workgroup_export)        create(          :netex_export, -        parent: workbench_export, +        parent: workgroup_export,          status: 'failed'        )        Timecop.freeze(Time.now) do -        workbench_export.update_status +        workgroup_export.update_status -        expect(workbench_export.ended_at).to eq(Time.now) +        expect(workgroup_export.ended_at).to eq(Time.now)        end      end    end diff --git a/spec/models/export/workbench_export_spec.rb b/spec/models/export/workbench_export_spec.rb deleted file mode 100644 index 1b2e81aa4..000000000 --- a/spec/models/export/workbench_export_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -RSpec.describe Export::Workbench, type: [:model, :with_commit] do -  it { should validate_presence_of(:timelapse) } - -  it "should set options" do -    expect(Export::Workbench.options).to have_key :timelapse -    expect(Export::Workbench.options[:timelapse][:required]).to be_truthy -    expect(Export::Workbench.options[:timelapse][:default_value]).to eq 90 -    expect(Export::Workbench.options[:timelapse][:type]).to eq :integer -  end -end diff --git a/spec/models/export/workgroup_export_spec.rb b/spec/models/export/workgroup_export_spec.rb new file mode 100644 index 000000000..c812b2b21 --- /dev/null +++ b/spec/models/export/workgroup_export_spec.rb @@ -0,0 +1,10 @@ +RSpec.describe Export::Workgroup, type: [:model, :with_commit] do +  it { should validate_presence_of(:duration) } + +  it "should set options" do +    expect(Export::Workgroup.options).to have_key :duration +    expect(Export::Workgroup.options[:duration][:required]).to be_truthy +    expect(Export::Workgroup.options[:duration][:default_value]).to eq 90 +    expect(Export::Workgroup.options[:duration][:type]).to eq :integer +  end +end diff --git a/spec/models/import/import_spec.rb b/spec/models/import/import_spec.rb index cbc5907fa..6b9201129 100644 --- a/spec/models/import/import_spec.rb +++ b/spec/models/import/import_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Import::Base, type: :model do    include ActionDispatch::TestProcess    it { should allow_value(fixture_file_upload('OFFRE_TRANSDEV_2017030112251.zip')).for(:file) } -  it { should_not allow_value(fixture_file_upload('users.json')).for(:file).with_message(I18n.t('errors.messages.extension_whitelist_error', extension: '"json"', allowed_types: "zip")) } +  it { should_not allow_value(fixture_file_upload('reflex_updated.xml')).for(:file).with_message(I18n.t('errors.messages.extension_whitelist_error', extension: '"xml"', allowed_types: "zip, csv, json")) }    let(:workbench_import) {netex_import.parent}    let(:workbench_import_with_completed_steps) do @@ -24,7 +24,7 @@ RSpec.describe Import::Base, type: :model do    end    let(:netex_import) do -    build_stubbed( +    create(        :netex_import      )    end @@ -115,19 +115,18 @@ RSpec.describe Import::Base, type: :model do        allow(netex_import).to receive(:update)        expect(workbench_import).to receive(:child_change) - +      netex_import.status = :foo        netex_import.notify_parent      end      it "must update the :notified_parent_at field of the child import" do        allow(workbench_import).to receive(:child_change) - -      Timecop.freeze(DateTime.now) do -        expect(netex_import).to receive(:update).with( -          notified_parent_at: DateTime.now -        ) +      Timecop.freeze(Time.now) do +        netex_import.status = :bar          netex_import.notify_parent +        expect(netex_import.notified_parent_at).to eq Time.now +        expect(netex_import.reload.notified_parent_at).to eq Time.now        end      end    end diff --git a/spec/models/simple_exporter_spec.rb b/spec/models/simple_exporter_spec.rb index 75051aeb9..a42daafe1 100644 --- a/spec/models/simple_exporter_spec.rb +++ b/spec/models/simple_exporter_spec.rb @@ -5,7 +5,7 @@ RSpec.describe SimpleExporter do          SimpleExporter.define :foo          expect do            SimpleExporter.new(configuration_name: :test).export -        end.to raise_error +        end.to raise_error(RuntimeError)        end      end      context "with a complete configuration" do @@ -18,9 +18,9 @@ RSpec.describe SimpleExporter do        it "should define an exporter" do          expect{SimpleExporter.find_configuration(:foo)}.to_not raise_error          expect{SimpleExporter.new(configuration_name: :foo, filepath: "").export}.to_not raise_error -        expect{SimpleExporter.find_configuration(:bar)}.to raise_error -        expect{SimpleExporter.new(configuration_name: :bar, filepath: "")}.to raise_error -        expect{SimpleExporter.new(configuration_name: :bar, filepath: "").export}.to raise_error +        expect{SimpleExporter.find_configuration(:bar)}.to raise_error(RuntimeError) +        expect{SimpleExporter.new(configuration_name: :bar, filepath: "")}.to raise_error(RuntimeError) +        expect{SimpleExporter.new(configuration_name: :bar, filepath: "").export}.to raise_error(RuntimeError)          expect{SimpleExporter.create(configuration_name: :foo, filepath: "")}.to change{SimpleExporter.count}.by 1        end      end @@ -33,7 +33,7 @@ RSpec.describe SimpleExporter do              config.add_column :name              config.add_column :name            end -        end.to raise_error +        end.to raise_error(RuntimeError)        end      end    end diff --git a/spec/models/simple_importer_spec.rb b/spec/models/simple_importer_spec.rb index 5f9eb0651..8f4d7cfdd 100644 --- a/spec/models/simple_importer_spec.rb +++ b/spec/models/simple_importer_spec.rb @@ -6,7 +6,7 @@ RSpec.describe SimpleImporter do          SimpleImporter.define :foo          expect do            SimpleImporter.new(configuration_name: :foo, filepath: "").import -        end.to raise_error +        end.to raise_error(RuntimeError)        end      end      context "with a complete configuration" do @@ -20,8 +20,8 @@ RSpec.describe SimpleImporter do          expect{SimpleImporter.find_configuration(:foo)}.to_not raise_error          expect{SimpleImporter.new(configuration_name: :foo, filepath: "")}.to_not raise_error          expect{SimpleImporter.new(configuration_name: :foo, filepath: "").import}.to_not raise_error -        expect{SimpleImporter.find_configuration(:bar)}.to raise_error -        expect{SimpleImporter.new(configuration_name: :bar, filepath: "")}.to raise_error +        expect{SimpleImporter.find_configuration(:bar)}.to raise_error(RuntimeError) +        expect{SimpleImporter.new(configuration_name: :bar, filepath: "")}.to raise_error(RuntimeError)          expect{SimpleImporter.create(configuration_name: :foo, filepath: "")}.to change{SimpleImporter.count}.by 1        end      end @@ -49,7 +49,7 @@ RSpec.describe SimpleImporter do      end      it "should import the given file" do -      expect{importer.import verbose: true}.to change{Chouette::StopArea.count}.by 1 +      expect{importer.import verbose: false}.to change{Chouette::StopArea.count}.by 1        expect(importer.status).to eq "success"        stop = Chouette::StopArea.last        expect(stop.name).to eq "Nom du Stop" diff --git a/spec/services/parent_notifier_spec.rb b/spec/services/parent_notifier_spec.rb index d4ca73ab3..d2dc6b184 100644 --- a/spec/services/parent_notifier_spec.rb +++ b/spec/services/parent_notifier_spec.rb @@ -46,6 +46,8 @@ RSpec.describe ParentNotifier do          notified_parent_at: nil        ) +      Import::Base.where(id: netex_import).update_all notified_parent_at: nil +        expect(          ParentNotifier.new(Import::Base).objects_pending_notification        ).to eq([netex_import]) | 
