diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-10-05 09:01:12 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-10-05 09:04:13 +0200 |
commit | c468d7fedd88e2474fd74e804a954a154674c8a0 (patch) | |
tree | 85248855b7ee34957257d3809385e1e939cc6093 | |
parent | f854be5e64737a7432570e9ce9d3edc38819e50a (diff) | |
parent | 6e0254e8d3c1dce532208bc868427d17aabbce5a (diff) | |
download | rails-c468d7fedd88e2474fd74e804a954a154674c8a0.tar.gz rails-c468d7fedd88e2474fd74e804a954a154674c8a0.tar.bz2 rails-c468d7fedd88e2474fd74e804a954a154674c8a0.zip |
Merge pull request #21854 from morgoth/fix-serializing-at-option-in-aj-matchers
Fixed serializing `:at` option for `assert_eqnueued_with` and `assert_performed_with`
-rw-r--r-- | activejob/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activejob/lib/active_job/test_helper.rb | 15 | ||||
-rw-r--r-- | activejob/test/cases/test_helper_test.rb | 26 |
3 files changed, 38 insertions, 8 deletions
diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md index 988815fee2..79235019fe 100644 --- a/activejob/CHANGELOG.md +++ b/activejob/CHANGELOG.md @@ -1,3 +1,8 @@ +* Fixed serializing `:at` option for `assert_enqueued_with` + and `assert_performed_with`. + + *Wojciech Wnętrzak* + * Support passing array to `assert_enqueued_jobs` in `:only` option. *Wojciech Wnętrzak* diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index 666e984fe0..de79de59f8 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -226,6 +226,10 @@ module ActiveJob # assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low') do # MyJob.perform_later(1,2,3) # end + # + # assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon) do + # MyJob.set(wait_until: Date.tomorrow.noon).perform_later + # end # end def assert_enqueued_with(args = {}, &_block) original_enqueued_jobs = enqueued_jobs.dup @@ -248,6 +252,10 @@ module ActiveJob # assert_performed_with(job: MyJob, args: [1,2,3], queue: 'high') do # MyJob.perform_later(1,2,3) # end + # + # assert_performed_with(job: MyJob, at: Date.tomorrow.noon) do + # MyJob.set(wait_until: Date.tomorrow.noon).perform_later + # end # end def assert_performed_with(args = {}, &_block) original_performed_jobs = performed_jobs.dup @@ -307,11 +315,10 @@ module ActiveJob end def serialize_args_for_assertion(args) # :nodoc: - serialized_args = args.dup - if job_args = serialized_args.delete(:args) - serialized_args[:args] = ActiveJob::Arguments.serialize(job_args) + args.dup.tap do |serialized_args| + serialized_args[:args] = ActiveJob::Arguments.serialize(serialized_args[:args]) if serialized_args[:args] + serialized_args[:at] = serialized_args[:at].to_f if serialized_args[:at] end - serialized_args end def instantiate_job(payload) # :nodoc: diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb index 18cf35562b..a66f5d762c 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -218,6 +218,12 @@ class EnqueuedJobsTest < ActiveJob::TestCase end end + def test_assert_enqueued_job_with_at_option + assert_enqueued_with(job: HelloJob, at: Date.tomorrow.noon) do + HelloJob.set(wait_until: Date.tomorrow.noon).perform_later + end + end + def test_assert_enqueued_job_with_global_id_args ricardo = Person.new(9) assert_enqueued_with(job: HelloJob, args: [ricardo]) do @@ -439,14 +445,26 @@ class PerformedJobsTest < ActiveJob::TestCase def test_assert_performed_job_failure assert_raise ActiveSupport::TestCase::Assertion do - assert_performed_with(job: LoggingJob, at: Date.tomorrow.noon, queue: 'default') do - NestedJob.set(wait_until: Date.tomorrow.noon).perform_later + assert_performed_with(job: LoggingJob) do + HelloJob.perform_later end end assert_raise ActiveSupport::TestCase::Assertion do - assert_performed_with(job: NestedJob, at: Date.tomorrow.noon, queue: 'low') do - NestedJob.set(queue: 'low', wait_until: Date.tomorrow.noon).perform_later + assert_performed_with(job: HelloJob, queue: 'low') do + HelloJob.set(queue: 'important').perform_later + end + end + end + + def test_assert_performed_job_with_at_option + assert_performed_with(job: HelloJob, at: Date.tomorrow.noon) do + HelloJob.set(wait_until: Date.tomorrow.noon).perform_later + end + + assert_raise ActiveSupport::TestCase::Assertion do + assert_performed_with(job: HelloJob, at: Date.today.noon) do + HelloJob.set(wait_until: Date.tomorrow.noon).perform_later end end end |