diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-06-11 18:24:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-11 18:24:25 -0400 |
commit | 7f6af4b6274f2816ee8aa1dda7863b7d7f93d02f (patch) | |
tree | 730017ea5ba9fb2618683cdb65b8701400088a7f /activejob | |
parent | e5ba6b296b07ceeb1b2ff7610f3b1ce03d6542e6 (diff) | |
parent | 38c187b0cc211bf79207f4ae59deef6f522e1736 (diff) | |
download | rails-7f6af4b6274f2816ee8aa1dda7863b7d7f93d02f.tar.gz rails-7f6af4b6274f2816ee8aa1dda7863b7d7f93d02f.tar.bz2 rails-7f6af4b6274f2816ee8aa1dda7863b7d7f93d02f.zip |
Merge pull request #25367 from stephenminded/active_job_test_helper_custom_queue_adapter
Provide the ability to override the queue adapter used by jobs under test
Diffstat (limited to 'activejob')
-rw-r--r-- | activejob/lib/active_job/test_helper.rb | 15 | ||||
-rw-r--r-- | activejob/test/cases/test_helper_test.rb | 12 |
2 files changed, 26 insertions, 1 deletions
diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index 3feb82d432..e16af1947f 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -9,7 +9,7 @@ module ActiveJob to: :queue_adapter def before_setup # :nodoc: - test_adapter = ActiveJob::QueueAdapters::TestAdapter.new + test_adapter = queue_adapter_for_test @old_queue_adapters = (ActiveJob::Base.subclasses << ActiveJob::Base).select do |klass| # only override explicitly set adapters, a quirk of `class_attribute` @@ -32,6 +32,19 @@ module ActiveJob end end + # Specifies the queue adapter to use with all active job test helpers. + # + # Returns an instance of the queue adapter and defaults to + # <tt>ActiveJob::QueueAdapters::TestAdapter</tt>. + # + # Note: The adapter provided by this method must provide some additional + # methods from those expected of a standard <tt>ActiveJob::QueueAdapter</tt> + # in order to be used with the active job test helpers. Refer to + # <tt>ActiveJob::QueueAdapters::TestAdapter</tt>. + def queue_adapter_for_test + ActiveJob::QueueAdapters::TestAdapter.new + end + # Asserts that the number of enqueued jobs matches the given number. # # def test_jobs diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb index f7ee763e8a..3d863f5e65 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -509,3 +509,15 @@ class PerformedJobsTest < ActiveJob::TestCase assert_equal 2, ActiveJob::Base.queue_adapter.performed_jobs.count end end + +class OverrideQueueAdapterTest < ActiveJob::TestCase + class CustomQueueAdapter < ActiveJob::QueueAdapters::TestAdapter; end + + def queue_adapter_for_test + CustomQueueAdapter.new + end + + def test_assert_job_has_custom_queue_adapter_set + assert_instance_of CustomQueueAdapter, HelloJob.queue_adapter + end +end |