aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2015-07-23 18:45:07 -0400
committerJean Boussier <jean.boussier@gmail.com>2015-08-10 20:14:42 -0400
commitb6d3a478fa22365207637454e0ac5c805a67af06 (patch)
treee0800b4538d76415ab52fe637d7f06ad6d8cb02f /activejob/lib
parent628a23cdd230f7f830ecbba137ab2430f69e8db5 (diff)
downloadrails-b6d3a478fa22365207637454e0ac5c805a67af06.tar.gz
rails-b6d3a478fa22365207637454e0ac5c805a67af06.tar.bz2
rails-b6d3a478fa22365207637454e0ac5c805a67af06.zip
Make assert_enqueued_with and assert_performed_with returns the matched job
Diffstat (limited to 'activejob/lib')
-rw-r--r--activejob/lib/active_job/test_helper.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb
index e71a3b4f85..74a12884ff 100644
--- a/activejob/lib/active_job/test_helper.rb
+++ b/activejob/lib/active_job/test_helper.rb
@@ -233,10 +233,11 @@ module ActiveJob
args.assert_valid_keys(:job, :args, :at, :queue)
serialized_args = serialize_args_for_assertion(args)
yield
- matching_job = enqueued_jobs.any? do |job|
+ matching_job = enqueued_jobs.find do |job|
serialized_args.all? { |key, value| value == job[key] }
end
assert matching_job, "No enqueued job found with #{args}"
+ instanciate_job(matching_job)
ensure
queue_adapter.enqueued_jobs = original_enqueued_jobs + enqueued_jobs
end
@@ -254,10 +255,11 @@ module ActiveJob
args.assert_valid_keys(:job, :args, :at, :queue)
serialized_args = serialize_args_for_assertion(args)
perform_enqueued_jobs { yield }
- matching_job = performed_jobs.any? do |job|
+ matching_job = performed_jobs.find do |job|
serialized_args.all? { |key, value| value == job[key] }
end
assert matching_job, "No performed job found with #{args}"
+ instanciate_job(matching_job)
ensure
queue_adapter.performed_jobs = original_performed_jobs + performed_jobs
end
@@ -311,6 +313,13 @@ module ActiveJob
end
serialized_args
end
+
+ def instanciate_job(payload)
+ job = payload[:job].new(*payload[:args])
+ job.scheduled_at = Time.at(payload[:at]) if payload.key?(:at)
+ job.queue_name = payload[:queue]
+ job
+ end
end
end
end