Fix name extraction for module queue adapters
Before this change, setting a module as queue adapter would result in `queue_adapter_name` being `"module"`. This PR fixes the name extraction logic to handle module or class queue adapters.
This commit is contained in:
parent
02c1b7ac48
commit
6b4acb57e2
@ -43,7 +43,8 @@ def queue_adapter=(name_or_adapter)
|
||||
assign_adapter(name_or_adapter.to_s, queue_adapter)
|
||||
else
|
||||
if queue_adapter?(name_or_adapter)
|
||||
adapter_name = "#{name_or_adapter.class.name.demodulize.remove('Adapter').underscore}"
|
||||
adapter_class = name_or_adapter.is_a?(Module) ? name_or_adapter : name_or_adapter.class
|
||||
adapter_name = "#{adapter_class.name.demodulize.remove('Adapter').underscore}"
|
||||
assign_adapter(adapter_name, name_or_adapter)
|
||||
else
|
||||
raise ArgumentError
|
||||
|
@ -50,4 +50,23 @@ class QueueAdapterTest < ActiveJob::TestCase
|
||||
|
||||
assert_not_nil child_job_three.queue_adapter
|
||||
end
|
||||
|
||||
test "should extract a reasonable name from a class instance" do
|
||||
child_job = Class.new(ActiveJob::Base)
|
||||
child_job.queue_adapter = ActiveJob::QueueAdapters::StubOneAdapter.new
|
||||
assert_equal "stub_one", child_job.queue_adapter_name
|
||||
end
|
||||
|
||||
module StubThreeAdapter
|
||||
class << self
|
||||
def enqueue(*); end
|
||||
def enqueue_at(*); end
|
||||
end
|
||||
end
|
||||
|
||||
test "should extract a reasonable name from a class or module" do
|
||||
child_job = Class.new(ActiveJob::Base)
|
||||
child_job.queue_adapter = StubThreeAdapter
|
||||
assert_equal "stub_three", child_job.queue_adapter_name
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user