diff options
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/mail_scheduler/notification_service_worker_spec.rb | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/spec/workers/mail_scheduler/notification_service_worker_spec.rb b/spec/workers/mail_scheduler/notification_service_worker_spec.rb index 1033557ee88..5cfba01850c 100644 --- a/spec/workers/mail_scheduler/notification_service_worker_spec.rb +++ b/spec/workers/mail_scheduler/notification_service_worker_spec.rb @@ -9,6 +9,10 @@ describe MailScheduler::NotificationServiceWorker do ActiveJob::Arguments.serialize(args) end + def deserialize(args) + ActiveJob::Arguments.deserialize(args) + end + describe '#perform' do it 'deserializes arguments from global IDs' do expect(worker.notification_service).to receive(method).with(key) @@ -42,13 +46,48 @@ describe MailScheduler::NotificationServiceWorker do end end - describe '.perform_async' do + describe '.perform_async', :sidekiq do + around do |example| + Sidekiq::Testing.fake! { example.run } + end + it 'serializes arguments as global IDs when scheduling' do - Sidekiq::Testing.fake! do - described_class.perform_async(method, key) + described_class.perform_async(method, key) + + expect(described_class.jobs.count).to eq(1) + expect(described_class.jobs.first).to include('args' => [method, *serialize(key)]) + end + + context 'with ActiveController::Parameters' do + let(:parameters) { ActionController::Parameters.new(hash) } + + let(:hash) do + { + "nested" => { + "hash" => true + } + } + end + + context 'when permitted' do + before do + parameters.permit! + end + + it 'serializes as a serializable Hash' do + described_class.perform_async(method, parameters) - expect(described_class.jobs.count).to eq(1) - expect(described_class.jobs.first).to include('args' => [method, *serialize(key)]) + expect(described_class.jobs.count).to eq(1) + expect(deserialize(described_class.jobs.first['args'])) + .to eq([method, hash]) + end + end + + context 'when not permitted' do + it 'fails to serialize' do + expect { described_class.perform_async(method, parameters) } + .to raise_error(ActionController::UnfilteredParameters) + end end end end |