Skip to content

Commit 0f764b4

Browse files
authored
Merge pull request rails#47995 from Mangara/mangara-support-class-queue-adapters
Fix name extraction for module queue adapters
2 parents d8a8df3 + 6b4acb5 commit 0f764b4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

activejob/lib/active_job/queue_adapter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def queue_adapter=(name_or_adapter)
4343
assign_adapter(name_or_adapter.to_s, queue_adapter)
4444
else
4545
if queue_adapter?(name_or_adapter)
46-
adapter_name = "#{name_or_adapter.class.name.demodulize.remove('Adapter').underscore}"
46+
adapter_class = name_or_adapter.is_a?(Module) ? name_or_adapter : name_or_adapter.class
47+
adapter_name = "#{adapter_class.name.demodulize.remove('Adapter').underscore}"
4748
assign_adapter(adapter_name, name_or_adapter)
4849
else
4950
raise ArgumentError

activejob/test/cases/queue_adapter_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,23 @@ class QueueAdapterTest < ActiveJob::TestCase
5050

5151
assert_not_nil child_job_three.queue_adapter
5252
end
53+
54+
test "should extract a reasonable name from a class instance" do
55+
child_job = Class.new(ActiveJob::Base)
56+
child_job.queue_adapter = ActiveJob::QueueAdapters::StubOneAdapter.new
57+
assert_equal "stub_one", child_job.queue_adapter_name
58+
end
59+
60+
module StubThreeAdapter
61+
class << self
62+
def enqueue(*); end
63+
def enqueue_at(*); end
64+
end
65+
end
66+
67+
test "should extract a reasonable name from a class or module" do
68+
child_job = Class.new(ActiveJob::Base)
69+
child_job.queue_adapter = StubThreeAdapter
70+
assert_equal "stub_three", child_job.queue_adapter_name
71+
end
5372
end

0 commit comments

Comments
 (0)