From c95d5fb7f54c79baafde3f3c73ecc4e4b756820e Mon Sep 17 00:00:00 2001 From: pik Date: Sun, 9 Aug 2015 21:36:43 +0800 Subject: [PATCH] add failing specs for scheduled jobs --- spec/lib/client/middleware_spec.rb | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/spec/lib/client/middleware_spec.rb b/spec/lib/client/middleware_spec.rb index a9f38c46f..e788e2248 100644 --- a/spec/lib/client/middleware_spec.rb +++ b/spec/lib/client/middleware_spec.rb @@ -33,9 +33,33 @@ def perform(_) end describe 'when a job is already scheduled' do - before { MyUniqueWorker.perform_in(3600, 1) } - it 'rejects new jobs with the same argument' do - expect(MyUniqueWorker.perform_async(1)).to eq(nil) + before 'schedule a job' do + MyUniqueWorker.perform_in(3600, 1) + end + + context '#old_unique_for' do + + it 'rejects new scheduled jobs with the same argument' do + allow(SidekiqUniqueJobs.config).to receive(:unique_storage_method).and_return(:old) + expect(MyUniqueWorker.perform_in(1800, 1)).to eq(nil) + end + + it 'will run a job in real time with the same arguments' do + allow(SidekiqUniqueJobs.config).to receive(:unique_storage_method).and_return(:old) + expect(MyUniqueWorker.perform_async(1)).not_to eq(nil) + end + end + context '#new_unique_for' do + + it 'rejects new scheduled jobs with the same argument' do + allow(SidekiqUniqueJobs.config).to receive(:unique_storage_method).and_return(:new) + expect(MyUniqueWorker.perform_in(3600, 1)).to eq(nil) + end + + it 'will run a job in real time with the same arguments' do + allow(SidekiqUniqueJobs.config).to receive(:unique_storage_method).and_return(:new) + expect(MyUniqueWorker.perform_async(1)).not_to eq(nil) + end end end