diff options
| author | Teddy Wing | 2017-08-01 23:19:37 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-08-01 23:22:15 +0200 | 
| commit | 7ed3bded976d7b3538fd49a36c6e3e79e6fc56e8 (patch) | |
| tree | 1f6577ec5d2fc932fb6164ad7a3adbb059b9a689 | |
| parent | c0aff43cbd6f4b5c4d131e577b3ad91679883d63 (diff) | |
| download | chouette-core-7ed3bded976d7b3538fd49a36c6e3e79e6fc56e8.tar.bz2 | |
Import#notify_parent: Update :notified_parent_at
The `#notify_parent` method should update the `notified_parent_at` field
on the child import so we know not to query it in subsequent batches of
parent import notifications.
Add the Timecop gem in order to be able to safely test the DateTime
update.
Refs #3511
| -rw-r--r-- | Gemfile | 1 | ||||
| -rw-r--r-- | Gemfile.lock | 2 | ||||
| -rw-r--r-- | app/models/import.rb | 1 | ||||
| -rw-r--r-- | spec/models/import_spec.rb | 20 | 
4 files changed, 24 insertions, 0 deletions
| @@ -163,6 +163,7 @@ group :test do    gem 'simplecov', :require => false    gem 'simplecov-rcov', :require => false    gem 'htmlbeautifier' +  gem 'timecop'  end  group :test, :development, :dev do diff --git a/Gemfile.lock b/Gemfile.lock index 2239cf853..d03a26d18 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -525,6 +525,7 @@ GEM      thread (0.2.2)      thread_safe (0.3.6)      tilt (1.4.1) +    timecop (0.9.1)      transpec (3.3.0)        activesupport (>= 3.0, < 6.0)        astrolabe (~> 1.2) @@ -669,6 +670,7 @@ DEPENDENCIES    squeel!    teaspoon-jasmine    therubyracer (~> 0.12) +  timecop    transpec    uglifier (~> 2.7.2)    webmock diff --git a/app/models/import.rb b/app/models/import.rb index 731454e12..507b40f38 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -15,6 +15,7 @@ class Import < ActiveRecord::Base    def notify_parent      parent.child_change(self) +    update(notified_parent_at: DateTime.now)    end    def child_change(child) diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index d99376a90..0a484f906 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -18,10 +18,30 @@ RSpec.describe Import, :type => :model do          parent: workbench_import        ) +      allow(netex_import).to receive(:update) +        expect(workbench_import).to receive(:child_change).with(netex_import)        netex_import.notify_parent      end + +    it "must update the :notified_parent_at field of the child import" do +      workbench_import = build_stubbed(:workbench_import) +      netex_import = build_stubbed( +        :netex_import, +        parent: workbench_import +      ) + +      allow(workbench_import).to receive(:child_change) + +      Timecop.freeze(DateTime.now) do +        expect(netex_import).to receive(:update).with( +          notified_parent_at: DateTime.now +        ) + +        netex_import.notify_parent +      end +    end    end    describe "#child_change" do | 
