diff options
| author | Teddy Wing | 2018-02-07 12:56:08 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-02-08 11:29:31 +0100 | 
| commit | 871a088ccffc47e5e09272b3105dabecf10974a6 (patch) | |
| tree | cc5749c0300555051eae27b5328724ae25641d6f | |
| parent | 6134ed98a3fe29276a17a0d79a70a8ce3e3f548b (diff) | |
| download | chouette-core-871a088ccffc47e5e09272b3105dabecf10974a6.tar.bz2 | |
imports.rake(notify_parent): Use `ParentNotifier`
Replace `ParentImportNotifier` with the new generalised
`ParentNotifier`. This will allow us to use the same service for parent
notification of both imports and compliance check sets.
Delete the `ParentImportNotifier` class and spec as these are now
superseded by `ParentNotifier`.
Refs #4758
| -rw-r--r-- | app/services/parent_import_notifier.rb | 15 | ||||
| -rw-r--r-- | lib/tasks/imports.rake | 2 | ||||
| -rw-r--r-- | spec/services/parent_import_notifier_spec.rb | 90 | 
3 files changed, 1 insertions, 106 deletions
diff --git a/app/services/parent_import_notifier.rb b/app/services/parent_import_notifier.rb deleted file mode 100644 index 47e6755e4..000000000 --- a/app/services/parent_import_notifier.rb +++ /dev/null @@ -1,15 +0,0 @@ -class ParentImportNotifier -  def self.notify_when_finished(imports = nil) -    imports ||= imports_pending_notification -    imports.each(&:notify_parent) -  end - -  def self.imports_pending_notification -    Import -      .where( -        notified_parent_at: nil, -        status: Import.finished_statuses -      ) -      .where.not(parent: nil) -  end -end diff --git a/lib/tasks/imports.rake b/lib/tasks/imports.rake index 6bc84acc8..55e017e7f 100644 --- a/lib/tasks/imports.rake +++ b/lib/tasks/imports.rake @@ -1,6 +1,6 @@  namespace :import do    desc "Notify parent imports when children finish"    task notify_parent: :environment do -    ParentImportNotifier.notify_when_finished +    ParentNotifier.new(Import).notify_when_finished    end  end diff --git a/spec/services/parent_import_notifier_spec.rb b/spec/services/parent_import_notifier_spec.rb deleted file mode 100644 index 3ab505f88..000000000 --- a/spec/services/parent_import_notifier_spec.rb +++ /dev/null @@ -1,90 +0,0 @@ -RSpec.describe ParentImportNotifier do -  let(:workbench_import) { create(:workbench_import) } - -  describe ".notify_when_finished" do -    it "calls #notify_parent on finished imports" do -      workbench_import = build_stubbed(:workbench_import) - -      finished_statuses = [:failed, :successful, :aborted, :canceled] -      netex_imports = [] - -      finished_statuses.each do |status| -        netex_imports << build_stubbed( -          :netex_import, -          parent: workbench_import, -          status: status -        ) -      end - -      netex_imports.each do |netex_import| -        expect(netex_import).to receive(:notify_parent) -      end - -      ParentImportNotifier.notify_when_finished(netex_imports) -    end - -    it "doesn't call #notify_parent if its `notified_parent_at` is set" do -      netex_import = create( -        :netex_import, -        parent: workbench_import, -        status: :failed, -        notified_parent_at: DateTime.now -      ) - -      expect(netex_import).not_to receive(:notify_parent) - -      ParentImportNotifier.notify_when_finished -    end -  end - -  describe ".imports_pending_notification" do -    it "includes imports with a parent and `notified_parent_at` unset" do -      netex_import = create( -        :netex_import, -        parent: workbench_import, -        status: :successful, -        notified_parent_at: nil -      ) - -      expect( -        ParentImportNotifier.imports_pending_notification -      ).to eq([netex_import]) -    end - -    it "doesn't include imports without a parent" do -      create(:import, parent: nil) - -      expect( -        ParentImportNotifier.imports_pending_notification -      ).to be_empty -    end - -    it "doesn't include imports that aren't finished" do -      [:new, :pending, :running].each do |status| -        create( -          :netex_import, -          parent: workbench_import, -          status: status, -          notified_parent_at: nil -        ) -      end - -      expect( -        ParentImportNotifier.imports_pending_notification -      ).to be_empty -    end - -    it "doesn't include imports that have already notified their parent" do -      create( -        :netex_import, -        parent: workbench_import, -        status: :successful, -        notified_parent_at: DateTime.now -      ) - -      expect( -        ParentImportNotifier.imports_pending_notification -      ).to be_empty -    end -  end -end  | 
