diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-10-24 15:49:10 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-24 15:49:10 -0400 |
commit | d76d66fb554fc3267de93d780344815d05ae6533 (patch) | |
tree | f504440be674c1f5b82a788a58aa7564c28721fc /activejob | |
parent | d3e646595fb33fce131750fb558b72560afdeb3f (diff) | |
parent | 3ebc22903433b97b38935778b955b53bc90447f6 (diff) | |
download | rails-d76d66fb554fc3267de93d780344815d05ae6533.tar.gz rails-d76d66fb554fc3267de93d780344815d05ae6533.tar.bz2 rails-d76d66fb554fc3267de93d780344815d05ae6533.zip |
Merge pull request #34204 from XrXr/aj-test-helper-args
Include deserialized arguments in jobs returned by AJ test helpers
Diffstat (limited to 'activejob')
-rw-r--r-- | activejob/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activejob/lib/active_job/test_helper.rb | 6 | ||||
-rw-r--r-- | activejob/test/cases/test_helper_test.rb | 24 |
3 files changed, 20 insertions, 15 deletions
diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md index af5c197bac..768e6bd250 100644 --- a/activejob/CHANGELOG.md +++ b/activejob/CHANGELOG.md @@ -1,3 +1,8 @@ +* Include deserialized arguments in job instances returned from + `assert_enqueued_with` and `assert_performed_with` + + *Alan Wu* + * Allow `assert_enqueued_with`/`assert_performed_with` methods to accept a proc for the `args` argument. This is useful to check if only a subset of arguments matches your expectations. diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index 229855c5d9..0deb68d0d2 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -594,8 +594,7 @@ module ActiveJob def flush_enqueued_jobs(only: nil, except: nil, queue: nil) enqueued_jobs_with(only: only, except: except, queue: queue) do |payload| - args = ActiveJob::Arguments.deserialize(payload[:args]) - instantiate_job(payload.merge(args: args)).perform_now + instantiate_job(payload).perform_now queue_adapter.performed_jobs << payload end end @@ -613,7 +612,8 @@ module ActiveJob end def instantiate_job(payload) - job = payload[:job].new(*payload[:args]) + args = ActiveJob::Arguments.deserialize(payload[:args]) + job = payload[:job].new(*args) job.scheduled_at = Time.at(payload[:at]) if payload.key?(:at) job.queue_name = payload[:queue] job diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb index 83c71ab1c4..8dc32037ff 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -476,23 +476,23 @@ class EnqueuedJobsTest < ActiveJob::TestCase def test_assert_enqueued_with_returns job = assert_enqueued_with(job: LoggingJob) do - LoggingJob.set(wait_until: 5.minutes.from_now).perform_later(1, 2, 3) + LoggingJob.set(wait_until: 5.minutes.from_now).perform_later(1, 2, 3, keyword: true) end assert_instance_of LoggingJob, job assert_in_delta 5.minutes.from_now, job.scheduled_at, 1 assert_equal "default", job.queue_name - assert_equal [1, 2, 3], job.arguments + assert_equal [1, 2, 3, { keyword: true }], job.arguments end def test_assert_enqueued_with_with_no_block_returns - LoggingJob.set(wait_until: 5.minutes.from_now).perform_later(1, 2, 3) + LoggingJob.set(wait_until: 5.minutes.from_now).perform_later(1, 2, 3, keyword: true) job = assert_enqueued_with(job: LoggingJob) assert_instance_of LoggingJob, job assert_in_delta 5.minutes.from_now, job.scheduled_at, 1 assert_equal "default", job.queue_name - assert_equal [1, 2, 3], job.arguments + assert_equal [1, 2, 3, { keyword: true }], job.arguments end def test_assert_enqueued_with_failure @@ -1515,26 +1515,26 @@ class PerformedJobsTest < ActiveJob::TestCase end def test_assert_performed_with_returns - job = assert_performed_with(job: NestedJob, queue: "default") do - NestedJob.perform_later + job = assert_performed_with(job: LoggingJob, queue: "default") do + LoggingJob.perform_later(keyword: :sym) end - assert_instance_of NestedJob, job + assert_instance_of LoggingJob, job assert_nil job.scheduled_at - assert_equal [], job.arguments + assert_equal [{ keyword: :sym }], job.arguments assert_equal "default", job.queue_name end def test_assert_performed_with_without_block_returns - NestedJob.perform_later + LoggingJob.perform_later(keyword: :sym) perform_enqueued_jobs - job = assert_performed_with(job: NestedJob, queue: "default") + job = assert_performed_with(job: LoggingJob, queue: "default") - assert_instance_of NestedJob, job + assert_instance_of LoggingJob, job assert_nil job.scheduled_at - assert_equal [], job.arguments + assert_equal [{ keyword: :sym }], job.arguments assert_equal "default", job.queue_name end |