From abe1d0d346e9059d46caf62f3bde67df75a07540 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 30 Aug 2017 11:10:12 +0200 Subject: Import spec: Use new hash syntax --- spec/models/import_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 69c77da91..0aee62ec1 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, type: :model do it { should belong_to(:referential) } it { should belong_to(:workbench) } -- cgit v1.2.3 From 36c65586265bee358b37e824acde91adc7a61a34 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 30 Aug 2017 11:19:06 +0200 Subject: Import#child_change: Remove `child` argument It isn't used any more so get rid of it. I had forgotten to remove the argument from the place it was actually called in the code when I did this previously in 61817b2e7828455021bcec66e2d6da70f879e1c4. Actually, Alban hadn't modified the method signature in the code he gave me, I shouldn't have committed that change as him, my bad. The argument was added back in because it caused `#notify_parent` to fail. Update that method so it makes the correct method call. --- app/models/import.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/import.rb b/app/models/import.rb index cdda3d0dc..eb2428b2b 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -29,11 +29,11 @@ class Import < ActiveRecord::Base end def notify_parent - parent.child_change(self) + parent.child_change update(notified_parent_at: DateTime.now) end - def child_change(child) + def child_change return if self.class.finished_statuses.include?(status) update_status -- cgit v1.2.3 From 1f13f38190fe219220f6093204e79f6a13c3d1fc Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 30 Aug 2017 11:30:35 +0200 Subject: Import spec: Get a few old specs to pass Update the mock to include the `ended_at` field update that happens in the code to get these tests green again. Not sure if we're going to continue to use them in their current state, but we'll worry about that later. --- spec/models/import_spec.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 0aee62ec1..7069cd066 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -49,7 +49,7 @@ RSpec.describe Import, type: :model do end # TODO: Move most of these to #update_status - describe "#child_change", skip: "THE CODE CHANGED AND THESE SPECS NO LONGER WORK. FIX THEM ASAP!!!~!~!@~" do + describe "#child_change" do shared_examples( "updates :status to failed when child status indicates failure" ) do |failure_status| @@ -61,12 +61,15 @@ RSpec.describe Import, type: :model do status: failure_status ) - expect(workbench_import).to receive(:update).with( - current_step: 1, - status: 'failed' - ) + Timecop.freeze(Time.now) do + expect(workbench_import).to receive(:update).with( + current_step: 1, + ended_at: Time.now, + status: 'failed' + ) - workbench_import.child_change + workbench_import.child_change + end end end -- cgit v1.2.3 From 64c09eebdf75dd4ecb14be87e9f7710c3cd0f7b1 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 30 Aug 2017 11:32:21 +0200 Subject: Import spec: Use new `#update_referentials` method name This method name was changed in 46aafcc4dbc65ef3216fbcae3b11b263e1c025c0 because it handles multiple referentials now. Update the tests to reflect that. --- spec/models/import_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 7069cd066..46fd8e8b2 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -147,10 +147,10 @@ RSpec.describe Import, type: :model do workbench_import.child_change end - it "calls #update_referential" do + it "calls #update_referentials" do allow(workbench_import).to receive(:update) - expect(workbench_import).to receive(:update_referential) + expect(workbench_import).to receive(:update_referentials) workbench_import.child_change end end -- cgit v1.2.3 From 326275bdb3729877cb6b5ffb6ec74e0649a1dcdc Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 30 Aug 2017 11:46:55 +0200 Subject: Import spec: Move most `#child_change` specs to `#update_status` The new `#child_change` doesn't do a whole lot, so the specs that used to test it don't belong any more. Update them so they test `#update_status` instead, where this logic now lives. --- spec/models/import_spec.rb | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 46fd8e8b2..08a3c81c0 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -48,8 +48,23 @@ RSpec.describe Import, type: :model do end end - # TODO: Move most of these to #update_status describe "#child_change" do + it "calls #update_status" do + allow(workbench_import).to receive(:update) + + expect(workbench_import).to receive(:update_status) + workbench_import.child_change + end + + it "calls #update_referentials" do + allow(workbench_import).to receive(:update) + + expect(workbench_import).to receive(:update_referentials) + workbench_import.child_change + end + end + + describe "#update_status" do shared_examples( "updates :status to failed when child status indicates failure" ) do |failure_status| @@ -68,7 +83,7 @@ RSpec.describe Import, type: :model do status: 'failed' ) - workbench_import.child_change + workbench_import.update_status end end end @@ -119,7 +134,7 @@ RSpec.describe Import, type: :model do expect(workbench_import).not_to receive(:update) - workbench_import.child_change + workbench_import.update_status end end @@ -140,22 +155,6 @@ RSpec.describe Import, type: :model do "canceled" ) - it "calls #update_status" do - allow(workbench_import).to receive(:update) - - expect(workbench_import).to receive(:update_status) - workbench_import.child_change - end - - it "calls #update_referentials" do - allow(workbench_import).to receive(:update) - - expect(workbench_import).to receive(:update_referentials) - workbench_import.child_change - end - end - - describe "#update_status" do it "updates :ended_at to now when status is finished" do skip "Redo the `#update_status` code to make it easier to write this." end -- cgit v1.2.3 From 597224492453bd4b9c12edb9379fd9947c73cf23 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 30 Aug 2017 11:49:44 +0200 Subject: Import spec#update_status: Get rid of obsolete tests These tests fail and are now wrong. While we previously prevented updating the import object in the old code, now the `#update` method gets called no matter what. --- spec/models/import_spec.rb | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 08a3c81c0..7ab5c7b30 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -120,41 +120,6 @@ RSpec.describe Import, type: :model do # workbench_import.child_change # end - shared_examples( - "doesn't update :status if parent import status is finished" - ) do |finished_status| - it "doesn't update :status if parent import status is finished" do - workbench_import = build_stubbed( - :workbench_import, - total_steps: 2, - current_step: 2, - status: finished_status - ) - double('Import') - - expect(workbench_import).not_to receive(:update) - - workbench_import.update_status - end - end - - include_examples( - "doesn't update :status if parent import status is finished", - "successful" - ) - include_examples( - "doesn't update :status if parent import status is finished", - "failed" - ) - include_examples( - "doesn't update :status if parent import status is finished", - "aborted" - ) - include_examples( - "doesn't update :status if parent import status is finished", - "canceled" - ) - it "updates :ended_at to now when status is finished" do skip "Redo the `#update_status` code to make it easier to write this." end -- cgit v1.2.3 From f81bfd7f8aaf2efd36615b904b58a78bdee1fa81 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 30 Aug 2017 12:06:39 +0200 Subject: Import spec: Update status set to 'failed' tests The name doesn't really match what's happening, since no `child` is passed in as an argument any more. This just always happens any time there are one or more failing children. Remove the mock expectation because the extra fields don't really relate to what we're supposed to be testing here, namely `status`. --- spec/models/import_spec.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 7ab5c7b30..8614d6ec8 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -66,9 +66,9 @@ RSpec.describe Import, type: :model do describe "#update_status" do shared_examples( - "updates :status to failed when child status indicates failure" + "updates :status to failed when >=1 child has failing status" ) do |failure_status| - it "updates :status to failed when child status indicates failure" do + it "updates :status to failed when >=1 child has failing status" do workbench_import = create(:workbench_import) create( :netex_import, @@ -77,27 +77,23 @@ RSpec.describe Import, type: :model do ) Timecop.freeze(Time.now) do - expect(workbench_import).to receive(:update).with( - current_step: 1, - ended_at: Time.now, - status: 'failed' - ) - workbench_import.update_status + + expect(workbench_import.status).to eq('failed') end end end include_examples( - "updates :status to failed when child status indicates failure", + "updates :status to failed when >=1 child has failing status", "failed" ) include_examples( - "updates :status to failed when child status indicates failure", + "updates :status to failed when >=1 child has failing status", "aborted" ) include_examples( - "updates :status to failed when child status indicates failure", + "updates :status to failed when >=1 child has failing status", "canceled" ) -- cgit v1.2.3 From 6f9ab93c2af49d093a305d1dea904d5d53e74cb6 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 30 Aug 2017 18:05:16 +0200 Subject: Refs #4177 --- .../vehicle_journeys/components/tools/select2s/TimetableSelect2.js | 2 +- app/views/time_table_combinations/_form.html.slim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/TimetableSelect2.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/TimetableSelect2.js index 0d8e54b1e..5157300ba 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/TimetableSelect2.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/TimetableSelect2.js @@ -36,7 +36,7 @@ class BSelect4 extends React.Component{ let newParmas = params.term.split(" ") return { q: { - objectid_end_any: newParmas, + objectid_cont_any: newParmas, comment_cont_any: newParmas, m: 'or' } diff --git a/app/views/time_table_combinations/_form.html.slim b/app/views/time_table_combinations/_form.html.slim index 581f00457..8e2d77d46 100644 --- a/app/views/time_table_combinations/_form.html.slim +++ b/app/views/time_table_combinations/_form.html.slim @@ -7,7 +7,7 @@ abbr title='Champ requis' * = f.input :combined_type, as: :boolean, checked_value: 'time_table', unchecked_value: 'calendar', required: false, label: content_tag(:span, t("time_table_combinations.combined_type.#{@combination.combined_type}"), class: 'switch-label', data: { checkedValue: 'Calendriers', uncheckedValue: 'Modèles de calendriers' }), wrapper_html: { class: 'col-sm-8 col-xs-7' } - = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un calendrier...', term: 'comment_or_objectid_cont', url: referential_autocomplete_time_tables_path(@referential, format: :json, :source_id => @combination.source_id)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''} + = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un calendrier...', term: 'comment_cont_or_objectid_cont', url: referential_autocomplete_time_tables_path(@referential, format: :json, :source_id => @combination.source_id)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''} = f.input :calendar_id, as: :select, input_html: { class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un modèle de calendrier...', term: 'name_cont', url: autocomplete_calendars_path}}, wrapper_html: {class: @combination.combined_type != 'calendar' ? 'hidden' : ''} -- cgit v1.2.3 From 1886c0581fef1bd851710a1e15889ecd86b558b3 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 30 Aug 2017 18:17:06 +0200 Subject: Import spec: Remove `Timecop` from test that no longer needs it Since we're not verifying `ended_at`, we have no need for the `Timecop` block. --- spec/models/import_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 8614d6ec8..4d86c3195 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -76,11 +76,9 @@ RSpec.describe Import, type: :model do status: failure_status ) - Timecop.freeze(Time.now) do - workbench_import.update_status + workbench_import.update_status - expect(workbench_import.status).to eq('failed') - end + expect(workbench_import.status).to eq('failed') end end -- cgit v1.2.3 From 327593b347390b174c696fa2cd1f90223f23475a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 30 Aug 2017 18:18:53 +0200 Subject: Import spec: Rewrite test that checks 'successful' status on parent Getting rid of the other commented test that checks failure because that combination is no longer relevant and the basic failure cases are handled by the specs just above. --- spec/models/import_spec.rb | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 4d86c3195..22bbfab09 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -95,24 +95,19 @@ RSpec.describe Import, type: :model do "canceled" ) - # TODO: rewrite these for new #update_status - # it "updates :status to successful when #ready?" do - # expect(workbench_import).to receive(:update).with(status: 'successful') - # - # workbench_import.child_change - # end - # - # it "updates :status to failed when #ready? and child is failed" do - # build_stubbed( - # :netex_import, - # parent: workbench_import, - # status: :failed - # ) - # - # expect(workbench_import).to receive(:update).with(status: 'failed') - # - # workbench_import.child_change - # end + it "updates :status to successful when all children are successful" do + workbench_import = create(:workbench_import) + create_list( + :netex_import, + 2, + parent: workbench_import, + status: 'successful' + ) + + workbench_import.update_status + + expect(workbench_import.status).to eq('successful') + end it "updates :ended_at to now when status is finished" do skip "Redo the `#update_status` code to make it easier to write this." -- cgit v1.2.3 From 7220c54b4ec097bd5d7292cb0b7a068ddb726a7c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 30 Aug 2017 18:23:29 +0200 Subject: Import spec: Add test for 'failed' with comination of child statuses When any one of a parent import's children have failed, the parent import should get status 'failed'. --- spec/models/import_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 22bbfab09..2a0c7539e 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -109,6 +109,24 @@ RSpec.describe Import, type: :model do expect(workbench_import.status).to eq('successful') end + it "Updates :status to failed when any child has failed" do + workbench_import = create(:workbench_import) + [ + 'failed', + 'successful' + ].each do |status| + create( + :netex_import, + parent: workbench_import, + status: status + ) + end + + workbench_import.update_status + + expect(workbench_import.status).to eq('failed') + end + it "updates :ended_at to now when status is finished" do skip "Redo the `#update_status` code to make it easier to write this." end -- cgit v1.2.3 From bd7b3374f87f083ffcb2c9d5d52ac2f3d2049e2b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 30 Aug 2017 18:26:17 +0200 Subject: Import spec: Test that `ended_at` gets updated correctly --- spec/models/import_spec.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 2a0c7539e..cc0fdd4ce 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -128,7 +128,18 @@ RSpec.describe Import, type: :model do end it "updates :ended_at to now when status is finished" do - skip "Redo the `#update_status` code to make it easier to write this." + workbench_import = create(:workbench_import) + create( + :netex_import, + parent: workbench_import, + status: 'failed' + ) + + Timecop.freeze(Time.now) do + workbench_import.update_status + + expect(workbench_import.ended_at).to eq(Time.now) + end end end -- cgit v1.2.3 From 7669cd8ae27bcbb8dbf1b5a968d50a7977b78d60 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 30 Aug 2017 18:55:26 +0200 Subject: Import spec: Add basic tests for `#update_referentials` --- spec/models/import_spec.rb | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index cc0fdd4ce..941e5b386 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -143,5 +143,48 @@ RSpec.describe Import, type: :model do end end - # TODO: specs for #update_referential + describe "#update_referentials" do + it "doesn't update referentials if parent status isn't finished" do + workbench_import = create(:workbench_import, status: 'pending') + netex_import = create(:netex_import, parent: workbench_import) + netex_import.referential.update(ready: false) + + workbench_import.update_referentials + netex_import.referential.reload + + expect(netex_import.referential.ready).to be false + end + + shared_examples( + "makes child referentials `ready` when status is finished" + ) do |finished_status| + it "makes child referentials `ready` when status is finished" do + workbench_import = create(:workbench_import, status: finished_status) + netex_import = create(:netex_import, parent: workbench_import) + netex_import.referential.update(ready: false) + + workbench_import.update_referentials + netex_import.referential.reload + + expect(netex_import.referential.ready).to be true + end + end + + include_examples( + "makes child referentials `ready` when status is finished", + "successful" + ) + include_examples( + "makes child referentials `ready` when status is finished", + "failed" + ) + include_examples( + "makes child referentials `ready` when status is finished", + "aborted" + ) + include_examples( + "makes child referentials `ready` when status is finished", + "canceled" + ) + end end -- cgit v1.2.3