From 38c187b0cc211bf79207f4ae59deef6f522e1736 Mon Sep 17 00:00:00 2001
From: Steve Lounsbury <steve.lounsbury@shopify.com>
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/test/cases/test_helper_test.rb | 12 ++++++++++++
 1 file changed, 12 insertions(+)

(limited to 'activejob/test')

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
-- 
cgit v1.2.3