Fix queue adapter class delegation to point to `self.class`

Using `self` works by essentially pointing to the included class, in
this case `ActiveJob::Base`, so that'd end up delegating to
`ActiveJob::Base.queue_adapter` instead.
This commit is contained in:
Carlos Antonio da Silva 2019-09-23 21:50:49 -03:00
parent db6884a772
commit a08a069acd
2 changed files with 3 additions and 1 deletions

View File

@ -12,7 +12,7 @@ module ActiveJob
class_attribute :_queue_adapter_name, instance_accessor: false, instance_predicate: false
class_attribute :_queue_adapter, default: :async, instance_accessor: false, instance_predicate: false
delegate :queue_adapter, to: self
delegate :queue_adapter, to: :class
self.queue_adapter = :async
end

View File

@ -34,6 +34,7 @@ class QueueAdapterTest < ActiveJob::TestCase
assert_not_equal ActiveJob::Base.queue_adapter, child_job_one.queue_adapter
assert_equal "stub_one", child_job_one.queue_adapter_name
assert_kind_of ActiveJob::QueueAdapters::StubOneAdapter, child_job_one.queue_adapter
assert_kind_of ActiveJob::QueueAdapters::StubOneAdapter, child_job_one.new.queue_adapter
child_job_two = Class.new(ActiveJob::Base)
child_job_two.queue_adapter = :stub_two
@ -41,6 +42,7 @@ class QueueAdapterTest < ActiveJob::TestCase
assert_equal "stub_two", child_job_two.queue_adapter_name
assert_kind_of ActiveJob::QueueAdapters::StubTwoAdapter, child_job_two.queue_adapter
assert_kind_of ActiveJob::QueueAdapters::StubTwoAdapter, child_job_two.new.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"