Skip to content

Commit 74a4bf9

Browse files
rosaclaude
andcommitted
Cache ClientStub instances per name like real clients
When disabled, client_for now caches the ClientStub per name instead of returning a new instance each call. This ensures the same object is returned on repeated calls, which is needed for test expectations (e.g. Rspamd.outbound_client.expects(:check)). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 757f84f commit 74a4bf9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

lib/rspamd/rails.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ def setup(config)
1111
end
1212

1313
def client_for(name)
14-
return ClientStub.new unless enabled?
15-
16-
@clients[name] ||= build_client(name)
14+
clients[name] ||= enabled? ? build_client(name) : ClientStub.new
1715
end
1816

1917
def reset!
@@ -22,6 +20,10 @@ def reset!
2220
end
2321

2422
private
23+
def clients
24+
@clients ||= {}
25+
end
26+
2527
def enabled?
2628
@config&.dig(:enabled)
2729
end

0 commit comments

Comments
 (0)