aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorXinhui2016-09-29 16:17:13 +0200
committerXinhui2016-09-29 16:17:13 +0200
commita1fffa57564825303671c20e596f4fc944fbdd12 (patch)
treeefbfe652a11c48d4818a26b3686ca2f355e612d7 /spec
parentcecd26452ce1cb2486d926421c1ae6360c973d1b (diff)
downloadchouette-core-a1fffa57564825303671c20e596f4fc944fbdd12.tar.bz2
Refactoring StopAreaReferentialSync
Refs #1710
Diffstat (limited to 'spec')
-rw-r--r--spec/models/stop_area_referential_sync_spec.rb37
-rw-r--r--spec/tasks/reflex_rake_spec.rb5
-rw-r--r--spec/workers/stop_area_referential_sync_worker_spec.rb19
3 files changed, 56 insertions, 5 deletions
diff --git a/spec/models/stop_area_referential_sync_spec.rb b/spec/models/stop_area_referential_sync_spec.rb
index 5f1e1e124..dd6855632 100644
--- a/spec/models/stop_area_referential_sync_spec.rb
+++ b/spec/models/stop_area_referential_sync_spec.rb
@@ -6,4 +6,41 @@ RSpec.describe StopAreaReferentialSync, :type => :model do
end
it { is_expected.to belong_to(:stop_area_referential) }
+ it { is_expected.to have_many(:stop_area_referential_sync_messages) }
+
+ it 'should validate multiple sync instance' do
+ pending = create(:stop_area_referential_sync)
+ multiple = build(:stop_area_referential_sync, stop_area_referential: pending.stop_area_referential)
+ expect(multiple).to be_invalid
+ end
+
+ it 'should call StopAreaReferentialSyncWorker on create' do
+ expect(StopAreaReferentialSyncWorker).to receive(:perform_async)
+ create(:stop_area_referential_sync).run_callbacks(:commit)
+ end
+
+ describe 'states' do
+ let(:stop_area_referential_sync) { create(:stop_area_referential_sync) }
+
+ it 'should initialize with new state' do
+ expect(stop_area_referential_sync.new?).to be_truthy
+ end
+
+ it 'should log pending state change' do
+ expect(stop_area_referential_sync).to receive(:log_pending)
+ stop_area_referential_sync.run
+ end
+
+ it 'should log successful state change' do
+ expect(stop_area_referential_sync).to receive(:log_successful)
+ stop_area_referential_sync.run
+ stop_area_referential_sync.successful
+ end
+
+ it 'should log failed state change' do
+ expect(stop_area_referential_sync).to receive(:log_failed)
+ stop_area_referential_sync.run
+ stop_area_referential_sync.failed
+ end
+ end
end
diff --git a/spec/tasks/reflex_rake_spec.rb b/spec/tasks/reflex_rake_spec.rb
index e5320b429..46910de72 100644
--- a/spec/tasks/reflex_rake_spec.rb
+++ b/spec/tasks/reflex_rake_spec.rb
@@ -44,11 +44,6 @@ describe 'reflex:sync' do
Stif::ReflexSynchronization.synchronize
end
- it 'should log sync operations' do
- expect(StopAreaSyncOperation.count).to eq 2
- expect(StopAreaSyncOperation.take.status).to eq "ok"
- end
-
it 'should not create duplicate stop_area' do
expect(Chouette::StopArea.count).to eq 6
expect(Chouette::AccessPoint.count).to eq 2
diff --git a/spec/workers/stop_area_referential_sync_worker_spec.rb b/spec/workers/stop_area_referential_sync_worker_spec.rb
new file mode 100644
index 000000000..48b64e55e
--- /dev/null
+++ b/spec/workers/stop_area_referential_sync_worker_spec.rb
@@ -0,0 +1,19 @@
+require 'rails_helper'
+RSpec.describe StopAreaReferentialSyncWorker, type: :worker do
+ let!(:stop_area_referential_sync) { create :stop_area_referential_sync }
+
+ it 'should call reflex synchronize on worker perform' do
+ expect(Stif::ReflexSynchronization).to receive(:synchronize)
+ StopAreaReferentialSyncWorker.new.perform(stop_area_referential_sync.id)
+ end
+
+ it 'should update stop_area_referential_sync started_at on worker perform' do
+ StopAreaReferentialSyncWorker.new.perform(stop_area_referential_sync.id)
+ expect(stop_area_referential_sync.reload.started_at).not_to be_nil
+ end
+
+ it 'should update stop_area_referential_sync ended_at on worker perform success' do
+ StopAreaReferentialSyncWorker.new.perform(stop_area_referential_sync.id)
+ expect(stop_area_referential_sync.reload.started_at).not_to be_nil
+ end
+end