diff options
author | Peter Leitzen <pleitzen@gitlab.com> | 2019-02-05 10:39:14 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-02-05 10:39:14 +0000 |
commit | 8dd3dc182e60224931034a692ec1be06a7d6e3df (patch) | |
tree | d652c281abc907d124a78155d40ce840725a31e9 /spec/workers | |
parent | 97041bb6c480e94593b1b7ee3102149ad30804dc (diff) | |
download | gitlab-ce-8dd3dc182e60224931034a692ec1be06a7d6e3df.tar.gz |
Make `ActionContorller::Parameters` serializable for sidekiq jobs
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 |