diff options
author | Tamir Duberstein <tamird@squareup.com> | 2014-09-23 20:43:12 -0700 |
---|---|---|
committer | Tamir Duberstein <tamird@gmail.com> | 2015-03-11 22:45:59 -0700 |
commit | 1f8558fa2707e7707dcfef0aba94de9afcd05d3a (patch) | |
tree | 14eac3acdc47d2c667b63b2baedb2ec479e57fe7 /activejob/test | |
parent | 7884c8f88e6bf64fe228141720183297ec2fce02 (diff) | |
download | rails-1f8558fa2707e7707dcfef0aba94de9afcd05d3a.tar.gz rails-1f8558fa2707e7707dcfef0aba94de9afcd05d3a.tar.bz2 rails-1f8558fa2707e7707dcfef0aba94de9afcd05d3a.zip |
`ActiveJob::Base#queue_adapter` is now a `class_attribute`
This allows different `queue_adapters` to be used in each `ActiveJob`
class heirarchy. Previously, all subclasses used a single global queue
adapter.
Diffstat (limited to 'activejob/test')
-rw-r--r-- | activejob/test/cases/queue_adapter_test.rb | 42 | ||||
-rw-r--r-- | activejob/test/cases/test_case_test.rb | 9 |
2 files changed, 46 insertions, 5 deletions
diff --git a/activejob/test/cases/queue_adapter_test.rb b/activejob/test/cases/queue_adapter_test.rb index d801a0852c..fb3fdc392f 100644 --- a/activejob/test/cases/queue_adapter_test.rb +++ b/activejob/test/cases/queue_adapter_test.rb @@ -1,5 +1,19 @@ require 'helper' +module ActiveJob + module QueueAdapters + class StubOneAdapter + def enqueue(*); end + def enqueue_at(*); end + end + + class StubTwoAdapter + def enqueue(*); end + def enqueue_at(*); end + end + end +end + class QueueAdapterTest < ActiveJob::TestCase test 'should forbid nonsense arguments' do assert_raises(ArgumentError) { ActiveJob::Base.queue_adapter = Mutex } @@ -12,13 +26,31 @@ class QueueAdapterTest < ActiveJob::TestCase 'fake' end - def enqueue(*) - end - - def enqueue_at(*) - end + def enqueue(*); end + def enqueue_at(*); end end assert_deprecated { ActiveJob::Base.queue_adapter = klass } end + + test 'should allow overriding the queue_adapter at the child class level without affecting the parent or its sibling' do + base_queue_adapter = ActiveJob::Base.queue_adapter + + child_job_one = Class.new(ActiveJob::Base) + child_job_one.queue_adapter = :stub_one + + assert_not_equal ActiveJob::Base.queue_adapter, child_job_one.queue_adapter + assert_kind_of ActiveJob::QueueAdapters::StubOneAdapter, child_job_one.queue_adapter + + child_job_two = Class.new(ActiveJob::Base) + child_job_two.queue_adapter = :stub_two + + assert_kind_of ActiveJob::QueueAdapters::StubTwoAdapter, child_job_two.queue_adapter + assert_kind_of ActiveJob::QueueAdapters::StubOneAdapter, child_job_one.queue_adapter, "child_job_one's queue adapter should remain unchanged" + assert_equal base_queue_adapter, ActiveJob::Base.queue_adapter, "ActiveJob::Base's queue adapter should remain unchanged" + + child_job_three = Class.new(ActiveJob::Base) + + assert_not_nil child_job_three.queue_adapter + end end diff --git a/activejob/test/cases/test_case_test.rb b/activejob/test/cases/test_case_test.rb index bd23878b23..0a3a20d5a0 100644 --- a/activejob/test/cases/test_case_test.rb +++ b/activejob/test/cases/test_case_test.rb @@ -4,6 +4,15 @@ require 'jobs/logging_job' require 'jobs/nested_job' class ActiveJobTestCaseTest < ActiveJob::TestCase + # this tests that this job class doesn't get its adapter set. + # that's the correct behaviour since we don't want to break + # the `class_attribute` inheritence + class TestClassAttributeInheritenceJob < ActiveJob::Base + def self.queue_adapter=(*) + raise 'Attemping to break `class_attribute` inheritence, bad!' + end + end + def test_include_helper assert_includes self.class.ancestors, ActiveJob::TestHelper end |