1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use named parameters instead of assert_valid_keys

This commit is contained in:
Maxime Boisvert 2016-11-16 15:41:30 -05:00
parent 3b2346ea13
commit c061236cc7

View file

@ -232,16 +232,16 @@ module ActiveJob
# MyJob.set(wait_until: Date.tomorrow.noon).perform_later # MyJob.set(wait_until: Date.tomorrow.noon).perform_later
# end # end
# end # end
def assert_enqueued_with(args = {}) def assert_enqueued_with(job: nil, args: nil, at: nil, queue: nil)
original_enqueued_jobs_count = enqueued_jobs.count original_enqueued_jobs_count = enqueued_jobs.count
args.assert_valid_keys(:job, :args, :at, :queue) expected = { job: job, args: args, at: at, queue: queue }.compact
serialized_args = serialize_args_for_assertion(args) serialized_args = serialize_args_for_assertion(expected)
yield yield
in_block_jobs = enqueued_jobs.drop(original_enqueued_jobs_count) in_block_jobs = enqueued_jobs.drop(original_enqueued_jobs_count)
matching_job = in_block_jobs.find do |job| matching_job = in_block_jobs.find do |job|
serialized_args.all? { |key, value| value == job[key] } serialized_args.all? { |key, value| value == job[key] }
end end
assert matching_job, "No enqueued job found with #{args}" assert matching_job, "No enqueued job found with #{expected}"
instantiate_job(matching_job) instantiate_job(matching_job)
end end
@ -256,16 +256,16 @@ module ActiveJob
# MyJob.set(wait_until: Date.tomorrow.noon).perform_later # MyJob.set(wait_until: Date.tomorrow.noon).perform_later
# end # end
# end # end
def assert_performed_with(args = {}) def assert_performed_with(job: nil, args: nil, at: nil, queue: nil)
original_performed_jobs_count = performed_jobs.count original_performed_jobs_count = performed_jobs.count
args.assert_valid_keys(:job, :args, :at, :queue) expected = { job: job, args: args, at: at, queue: queue }.compact
serialized_args = serialize_args_for_assertion(args) serialized_args = serialize_args_for_assertion(expected)
perform_enqueued_jobs { yield } perform_enqueued_jobs { yield }
in_block_jobs = performed_jobs.drop(original_performed_jobs_count) in_block_jobs = performed_jobs.drop(original_performed_jobs_count)
matching_job = in_block_jobs.find do |job| matching_job = in_block_jobs.find do |job|
serialized_args.all? { |key, value| value == job[key] } serialized_args.all? { |key, value| value == job[key] }
end end
assert matching_job, "No performed job found with #{args}" assert matching_job, "No performed job found with #{expected}"
instantiate_job(matching_job) instantiate_job(matching_job)
end end