From 38c187b0cc211bf79207f4ae59deef6f522e1736 Mon Sep 17 00:00:00 2001 From: Steve Lounsbury Date: Sat, 11 Jun 2016 15:18:52 -0400 Subject: Provide the ability to override the queue adapter used by jobs under test. This PR adds a method called `queue_adapter_for_test` to `ActiveJob::TestHelper`. This method is expected to provide the queue adapter to be used for jobs under test. It maintains the current behaviour by defaulting to an instance of `ActiveJob::QueueAdapter::TestAdapter`. Tests that include `ActiveJob::TestHelper` or extend from `ActiveJob::TestCase` can provide a custom queue adapter by overriding `queue_adapter_for_test` in their class. --- activejob/lib/active_job/test_helper.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'activejob/lib') 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 + # ActiveJob::QueueAdapters::TestAdapter. + # + # Note: The adapter provided by this method must provide some additional + # methods from those expected of a standard ActiveJob::QueueAdapter + # in order to be used with the active job test helpers. Refer to + # ActiveJob::QueueAdapters::TestAdapter. + def queue_adapter_for_test + ActiveJob::QueueAdapters::TestAdapter.new + end + # Asserts that the number of enqueued jobs matches the given number. # # def test_jobs -- cgit v1.2.3