diff options
author | Jeremy Kemper <jeremykemper@gmail.com> | 2015-03-06 10:41:46 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremykemper@gmail.com> | 2015-03-06 10:42:49 -0700 |
commit | a3e490419a2c6d36360e9186973ebbee6335623d (patch) | |
tree | 22e14c8e0c1fc4f345c3c582d4b991fa2c9e6f80 | |
parent | e81693a0ebce0d1f6f259230847bca0109192c71 (diff) | |
download | rails-a3e490419a2c6d36360e9186973ebbee6335623d.tar.gz rails-a3e490419a2c6d36360e9186973ebbee6335623d.tar.bz2 rails-a3e490419a2c6d36360e9186973ebbee6335623d.zip |
Fix leaky `only: …` option for Active Job assertions
The filter was set on the pseudo-global TestAdapter but not restored to
its original value.
See e818f65770fe115ab1cc7fbacc0e7e94d92af6a4
-rw-r--r-- | activejob/lib/active_job/test_helper.rb | 24 | ||||
-rw-r--r-- | activejob/test/cases/test_helper_test.rb | 8 |
2 files changed, 23 insertions, 9 deletions
diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index 66508114d1..bb8b267c31 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -13,6 +13,7 @@ module ActiveJob clear_performed_jobs queue_adapter.perform_enqueued_jobs = false queue_adapter.perform_enqueued_at_jobs = false + queue_adapter.filter = nil super end @@ -253,15 +254,20 @@ module ActiveJob end def perform_enqueued_jobs(only: nil) - @old_perform_enqueued_jobs = queue_adapter.perform_enqueued_jobs - @old_perform_enqueued_at_jobs = queue_adapter.perform_enqueued_at_jobs - queue_adapter.perform_enqueued_jobs = true - queue_adapter.perform_enqueued_at_jobs = true - queue_adapter.filter = only - yield - ensure - queue_adapter.perform_enqueued_jobs = @old_perform_enqueued_jobs - queue_adapter.perform_enqueued_at_jobs = @old_perform_enqueued_at_jobs + old_perform_enqueued_jobs = queue_adapter.perform_enqueued_jobs + old_perform_enqueued_at_jobs = queue_adapter.perform_enqueued_at_jobs + old_filter = queue_adapter.filter + + begin + queue_adapter.perform_enqueued_jobs = true + queue_adapter.perform_enqueued_at_jobs = true + queue_adapter.filter = only + yield + ensure + queue_adapter.perform_enqueued_jobs = old_perform_enqueued_jobs + queue_adapter.perform_enqueued_at_jobs = old_perform_enqueued_at_jobs + queue_adapter.filter = old_filter + end end def queue_adapter diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb index 58de2f2588..19a2820a6e 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -199,6 +199,14 @@ class EnqueuedJobsTest < ActiveJob::TestCase end class PerformedJobsTest < ActiveJob::TestCase + def test_performed_enqueue_jobs_with_only_option_doesnt_leak_outside_the_block + assert_equal nil, queue_adapter.filter + perform_enqueued_jobs only: HelloJob do + assert_equal HelloJob, queue_adapter.filter + end + assert_equal nil, queue_adapter.filter + end + def test_assert_performed_jobs assert_nothing_raised do assert_performed_jobs 1 do |