diff options
author | Richard Schneeman <richard.schneeman@gmail.com> | 2015-10-07 15:39:42 -0500 |
---|---|---|
committer | Richard Schneeman <richard.schneeman@gmail.com> | 2015-10-07 15:39:42 -0500 |
commit | 5ddf6df9665c2af2f52593090694327cd9507454 (patch) | |
tree | cf8f139736d3025f5000a67b68e62864ea8bb653 /activejob/lib/active_job/test_helper.rb | |
parent | 172c25e7b62b4b7f7c8ef7c7174ed4d17c8dacfe (diff) | |
parent | c2854af74784a059318d691d4e021c04719028cf (diff) | |
download | rails-5ddf6df9665c2af2f52593090694327cd9507454.tar.gz rails-5ddf6df9665c2af2f52593090694327cd9507454.tar.bz2 rails-5ddf6df9665c2af2f52593090694327cd9507454.zip |
Merge pull request #21904 from morgoth/missing-test-for-not-modifing-queues
Added missing specs for not modifying queues when using AJ test helpers
Diffstat (limited to 'activejob/lib/active_job/test_helper.rb')
-rw-r--r-- | activejob/lib/active_job/test_helper.rb | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index de79de59f8..44ddfa5f69 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -231,19 +231,17 @@ module ActiveJob # MyJob.set(wait_until: Date.tomorrow.noon).perform_later # end # end - def assert_enqueued_with(args = {}, &_block) - original_enqueued_jobs = enqueued_jobs.dup - clear_enqueued_jobs + def assert_enqueued_with(args = {}) + original_enqueued_jobs_count = enqueued_jobs.count args.assert_valid_keys(:job, :args, :at, :queue) serialized_args = serialize_args_for_assertion(args) yield - matching_job = enqueued_jobs.find do |job| + in_block_jobs = enqueued_jobs.drop(original_enqueued_jobs_count) + matching_job = in_block_jobs.find do |job| serialized_args.all? { |key, value| value == job[key] } end assert matching_job, "No enqueued job found with #{args}" instantiate_job(matching_job) - ensure - queue_adapter.enqueued_jobs = original_enqueued_jobs + enqueued_jobs end # Asserts that the job passed in the block has been performed with the given arguments. @@ -257,19 +255,17 @@ module ActiveJob # MyJob.set(wait_until: Date.tomorrow.noon).perform_later # end # end - def assert_performed_with(args = {}, &_block) - original_performed_jobs = performed_jobs.dup - clear_performed_jobs + def assert_performed_with(args = {}) + original_performed_jobs_count = performed_jobs.count args.assert_valid_keys(:job, :args, :at, :queue) serialized_args = serialize_args_for_assertion(args) perform_enqueued_jobs { yield } - matching_job = performed_jobs.find do |job| + in_block_jobs = performed_jobs.drop(original_performed_jobs_count) + matching_job = in_block_jobs.find do |job| serialized_args.all? { |key, value| value == job[key] } end assert matching_job, "No performed job found with #{args}" instantiate_job(matching_job) - ensure - queue_adapter.performed_jobs = original_performed_jobs + performed_jobs end def perform_enqueued_jobs(only: nil) @@ -308,9 +304,9 @@ module ActiveJob def enqueued_jobs_size(only: nil) # :nodoc: if only - enqueued_jobs.select { |job| Array(only).include?(job.fetch(:job)) }.size + enqueued_jobs.count { |job| Array(only).include?(job.fetch(:job)) } else - enqueued_jobs.size + enqueued_jobs.count end end |