Skip to content

Commit 0ad566e

Browse files
BBrannickclaude
andcommitted
Accept any Que::Adapters::Base subclass in Que.connection=
Replace the hardcoded class-name whitelist with an is_a?(Adapters::Base) guard, so external adapter subclasses (e.g. defined in consuming apps) can be passed directly without raising "Que connection not recognized". Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2e7e4c1 commit 0ad566e

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

lib/que.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ def connection=(connection)
6262
self.adapter =
6363
if connection.to_s == "ActiveRecord"
6464
Adapters::ActiveRecord.new
65+
elsif connection.is_a?(Adapters::Base)
66+
connection
6567
else
6668
case connection.class.to_s
67-
when "Que::Adapters::ActiveRecordWithLock" then connection
6869
when "Sequel::Postgres::Database" then Adapters::Sequel.new(connection)
6970
when "ConnectionPool" then Adapters::ConnectionPool.new(connection)
7071
when "PG::Connection" then Adapters::PG.new(connection)

spec/lib/que/que_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
RSpec.describe Que do
6+
describe ".connection=" do
7+
it "accepts a custom Adapters::Base subclass instance and sets it as the adapter" do
8+
custom_adapter_class = Class.new(Que::Adapters::Base)
9+
stub_const("MyApp::CustomAdapter", custom_adapter_class)
10+
custom_adapter = MyApp::CustomAdapter.new
11+
12+
expect { Que.connection = custom_adapter }.not_to raise_error
13+
expect(Que.adapter).to eq(custom_adapter)
14+
end
15+
16+
it "raises for an unrecognized non-adapter object" do
17+
expect { Que.connection = Object.new }.
18+
to raise_error(/Que connection not recognized/)
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)