diff options
| author | Alban Peignier | 2018-03-21 17:06:46 +0100 |
|---|---|---|
| committer | Luc Donnet | 2018-03-23 17:21:56 +0100 |
| commit | 6d485b9bae94c1251c5e3f89219fcd29128c49d6 (patch) | |
| tree | 45170f32e0284c9db2997c318881d6ffdd986bb9 | |
| parent | 7e5cebd76f7aef72028f1ea944c02fe06eeb657b (diff) | |
| download | chouette-core-6d485b9bae94c1251c5e3f89219fcd29128c49d6.tar.bz2 | |
Only notify parent when Import is finished. Refs #6243
| -rw-r--r-- | app/models/concerns/iev_interfaces/task.rb | 2 | ||||
| -rw-r--r-- | spec/controllers/api/v1/internals/netex_imports_controller_spec.rb | 7 | ||||
| -rw-r--r-- | spec/models/export/base_spec.rb | 47 | ||||
| -rw-r--r-- | spec/models/import/import_spec.rb | 44 |
4 files changed, 75 insertions, 25 deletions
diff --git a/app/models/concerns/iev_interfaces/task.rb b/app/models/concerns/iev_interfaces/task.rb index 99b9be0d8..bc78ff28c 100644 --- a/app/models/concerns/iev_interfaces/task.rb +++ b/app/models/concerns/iev_interfaces/task.rb @@ -52,6 +52,8 @@ module IevInterfaces::Task end def notify_parent + return unless self.class.finished_statuses.include?(status) + return unless parent.present? return if notified_parent_at parent.child_change diff --git a/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb b/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb index ccdc258f4..b53ee3f05 100644 --- a/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb +++ b/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb @@ -1,6 +1,6 @@ RSpec.describe Api::V1::Internals::NetexImportsController, type: :controller do let(:import_1) { create :netex_import } - let(:import_2) { create :netex_import } + let(:import_2) { create :netex_import, status: "successful" } describe "GET #notify_parent" do context 'unauthenticated' do @@ -17,14 +17,14 @@ RSpec.describe Api::V1::Internals::NetexImportsController, type: :controller do describe "with existing record" do - before(:each) do + before(:each) do get :notify_parent, id: import_2.id, format: :json end it 'should be successful' do expect(response).to have_http_status 200 end - + it "calls #notify_parent on the import" do expect(import_2.reload.notified_parent_at).not_to be_nil end @@ -39,4 +39,3 @@ RSpec.describe Api::V1::Internals::NetexImportsController, type: :controller do end end end - diff --git a/spec/models/export/base_spec.rb b/spec/models/export/base_spec.rb index da52fa1f3..9faf31e38 100644 --- a/spec/models/export/base_spec.rb +++ b/spec/models/export/base_spec.rb @@ -110,24 +110,49 @@ RSpec.describe Export::Base, type: :model do end describe "#notify_parent" do - it "must call #child_change on its parent" do - allow(netex_export).to receive(:update) + context "when export is finished" do + before do + netex_export.status = "successful" + netex_export.notified_parent_at = nil + end - expect(workgroup_export).to receive(:child_change) - netex_export.notified_parent_at = nil - netex_export.notify_parent - end + it "must call #child_change on its parent" do + allow(netex_export).to receive(:update) - it "must update the :notified_parent_at field of the child export" do - allow(workgroup_export).to receive(:child_change) + expect(workgroup_export).to receive(:child_change) + netex_export.notified_parent_at = nil + netex_export.notify_parent + end - Timecop.freeze(Time.now) do + it "must update the :notified_parent_at field of the child export" do + allow(workgroup_export).to receive(:child_change) + + Timecop.freeze(Time.now) do + netex_export.notify_parent + expect(netex_export.notified_parent_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') + expect(netex_export.reload.notified_parent_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') + end + end + end + + context "when export is not finished" do + before do + netex_export.status = "running" netex_export.notified_parent_at = nil + end + + it "must not call #child_change on its parent" do + allow(netex_export).to receive(:update) + expect(workgroup_export).to_not receive(:child_change) netex_export.notify_parent - expect(netex_export.notified_parent_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') - expect(netex_export.reload.notified_parent_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') end + + it "must keep nil the :notified_parent_at field of the child export" do + netex_export.notify_parent + expect(netex_export.notified_parent_at).to be_nil + end + end end diff --git a/spec/models/import/import_spec.rb b/spec/models/import/import_spec.rb index ab8fcc9c0..73670b60f 100644 --- a/spec/models/import/import_spec.rb +++ b/spec/models/import/import_spec.rb @@ -111,23 +111,47 @@ RSpec.describe Import::Base, type: :model do end describe "#notify_parent" do - it "must call #child_change on its parent" do - allow(netex_import).to receive(:update) + context "when import is finished" do + before do + netex_import.status = "successful" + netex_import.notified_parent_at = nil + end - expect(workbench_import).to receive(:child_change) - netex_import.notified_parent_at = nil - netex_import.notify_parent + it "must call #child_change on its parent" do + allow(netex_import).to receive(:update) + + expect(workbench_import).to receive(:child_change) + 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(Time.now) do + netex_import.notify_parent + expect(netex_import.notified_parent_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') + expect(netex_import.reload.notified_parent_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') + end + end end - it "must update the :notified_parent_at field of the child import" do - allow(workbench_import).to receive(:child_change) - Timecop.freeze(Time.now) do + context "when import is not finished" do + before do + netex_import.status = "running" netex_import.notified_parent_at = nil + end + it "must not call #child_change on its parent" do + allow(netex_import).to receive(:update) + + expect(workbench_import).to_not receive(:child_change) netex_import.notify_parent - expect(netex_import.notified_parent_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') - expect(netex_import.reload.notified_parent_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') end + + it "must keep nil the :notified_parent_at field of the child import" do + netex_import.notify_parent + expect(netex_import.notified_parent_at).to be_nil + end + end end |
