diff options
-rw-r--r-- | activejob/lib/active_job/queue_adapters/test_adapter.rb | 24 | ||||
-rw-r--r-- | activejob/lib/active_job/test_case.rb | 3 | ||||
-rw-r--r-- | activejob/lib/active_job/test_helper.rb | 29 | ||||
-rw-r--r-- | activejob/test/cases/test_case_test.rb | 1 | ||||
-rw-r--r-- | activejob/test/cases/test_helper_test.rb | 5 |
5 files changed, 31 insertions, 31 deletions
diff --git a/activejob/lib/active_job/queue_adapters/test_adapter.rb b/activejob/lib/active_job/queue_adapters/test_adapter.rb index 2cab9e946d..971db9d7de 100644 --- a/activejob/lib/active_job/queue_adapters/test_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/test_adapter.rb @@ -6,10 +6,10 @@ module ActiveJob # Provides a store of all the enqueued jobs with the TestAdapter so you can check them. def enqueued_jobs - @@enqueued_jobs ||= [] + @enqueued_jobs ||= [] end - # Allows you to over write the default enqueued jobs store from an array to some + # Allows you to overwrite the default enqueued jobs store from an array to some # other object. If you just want to clear the store, # call ActiveJob::QueueAdapters::TestAdapter.enqueued_jobs.clear. # @@ -21,15 +21,15 @@ module ActiveJob # * size # * and other common Array methods def enqueued_jobs=(val) - @@enqueued_jobs = val + @enqueued_jobs = val end # Provides a store of all the performed jobs with the TestAdapter so you can check them. def performed_jobs - @@performed_jobs ||= [] + @performed_jobs ||= [] end - # Allows you to over write the default performed jobs store from an array to some + # Allows you to overwrite the default performed jobs store from an array to some # other object. If you just want to clear the store, # call ActiveJob::QueueAdapters::TestAdapter.performed_jobs.clear. # @@ -41,7 +41,7 @@ module ActiveJob # * size # * and other common Array methods def performed_jobs=(val) - @@performed_jobs = val + @performed_jobs = val end def enqueue(job, *args) @@ -63,13 +63,13 @@ module ActiveJob end private - def perform_enqueued_jobs? - perform_enqueued_jobs - end + def perform_enqueued_jobs? + perform_enqueued_jobs + end - def perform_enqueued_at_jobs? - perform_enqueued_at_jobs - end + def perform_enqueued_at_jobs? + perform_enqueued_at_jobs + end end end end diff --git a/activejob/lib/active_job/test_case.rb b/activejob/lib/active_job/test_case.rb index f22e4e2ead..d894a7b5cd 100644 --- a/activejob/lib/active_job/test_case.rb +++ b/activejob/lib/active_job/test_case.rb @@ -1,8 +1,7 @@ -# encoding: utf-8 require 'active_support/test_case' module ActiveJob class TestCase < ActiveSupport::TestCase - include ActiveJob::TestHelper + include ActiveJob::TestHelper end end diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index 2323ca13db..767619097c 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -1,13 +1,21 @@ -# encoding: utf-8 module ActiveJob # Provides helper methods for testing Active Job module TestHelper extend ActiveSupport::Concern - include ActiveSupport::Testing::ConstantLookup included do - class_attribute :_job_class - setup :initialize_queue_test_adapter + def before_setup + @old_queue_adapter = queue_adapter + ActiveJob::Base.queue_adapter = :test + clear_enqueued_jobs + clear_performed_jobs + super + end + + def after_teardown + super + ActiveJob::Base.queue_adapter = @old_queue_adapter + end # Asserts that the number of enqueued jobs matches the given number. # @@ -40,7 +48,8 @@ module ActiveJob assert_equal original_count + number, new_count, "#{number} jobs expected, but #{new_count - original_count} were enqueued" else - assert_equal number, enqueued_jobs.size + enqueued_jobs_size = enqueued_jobs.size + assert_equal number, enqueued_jobs_size, "#{number} jobs expected, but #{enqueued_jobs_size} were enqueued" end end @@ -98,7 +107,8 @@ module ActiveJob assert_equal original_count + number, new_count, "#{number} jobs expected, but #{new_count - original_count} were performed" else - assert_equal number, performed_jobs.size + performed_jobs_size = performed_jobs.size + assert_equal number, performed_jobs_size, "#{number} jobs expected, but #{performed_jobs_size} were performed" end end @@ -165,7 +175,6 @@ module ActiveJob queue_adapter.performed_jobs = original_performed_jobs + performed_jobs end - def queue_adapter ActiveJob::Base.queue_adapter end @@ -175,12 +184,6 @@ module ActiveJob to: :queue_adapter private - def initialize_queue_test_adapter - ActiveJob::Base.queue_adapter = :test - clear_enqueued_jobs - clear_performed_jobs - end - def clear_enqueued_jobs enqueued_jobs.clear end diff --git a/activejob/test/cases/test_case_test.rb b/activejob/test/cases/test_case_test.rb index 802a796fd1..1d0fdbd22d 100644 --- a/activejob/test/cases/test_case_test.rb +++ b/activejob/test/cases/test_case_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 require 'helper' require 'jobs/hello_job' require 'jobs/logging_job' diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb index ee558e6d59..240aa23ce3 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 require 'helper' require 'active_support/core_ext/time' require 'active_support/core_ext/date' @@ -74,7 +73,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase assert_match(/1 .* but 2/, error.message) end - # + def test_assert_no_enqueued_jobs_failure error = assert_raise ActiveSupport::TestCase::Assertion do assert_no_enqueued_jobs do @@ -182,7 +181,7 @@ class PerformedJobsTest < ActiveJob::TestCase assert_match(/1 .* but 2/, error.message) end - # + def test_assert_no_performed_jobs_failure error = assert_raise ActiveSupport::TestCase::Assertion do assert_no_performed_jobs do |