aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/cases/test_helper_test.rb
diff options
context:
space:
mode:
authorSteve Lounsbury <steve.lounsbury@shopify.com>2016-06-11 15:18:52 -0400
committerSteve Lounsbury <steve.lounsbury@shopify.com>2016-06-11 15:18:52 -0400
commit38c187b0cc211bf79207f4ae59deef6f522e1736 (patch)
treec7ff0dc675771bb898d16dc34dd25ffe0208dba6 /activejob/test/cases/test_helper_test.rb
parentf45d06e11fdacf45df55b7b6f20b4987fe367109 (diff)
downloadrails-38c187b0cc211bf79207f4ae59deef6f522e1736.tar.gz
rails-38c187b0cc211bf79207f4ae59deef6f522e1736.tar.bz2
rails-38c187b0cc211bf79207f4ae59deef6f522e1736.zip
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.
Diffstat (limited to 'activejob/test/cases/test_helper_test.rb')
-rw-r--r--activejob/test/cases/test_helper_test.rb12
1 files changed, 12 insertions, 0 deletions
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