Skip to content

Commit 838eea4

Browse files
authored
make sure to evaluate client name since it might be a proc (#5906) (#5907)
1 parent fde698f commit 838eea4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/mongoid/persistence_context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def client
138138
# @return [ Symbol ] The client name for this persistence
139139
# context.
140140
def client_name
141-
@client_name ||= options[:client] ||
141+
@client_name ||= __evaluate__(options[:client]) ||
142142
Threaded.client_override ||
143143
__evaluate__(storage_options[:client])
144144
end

spec/mongoid/persistence_context_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,14 @@
584584
expect(persistence_context.client).to eq(Mongoid::Clients.with_name(:alternative))
585585
end
586586

587+
context 'when the client option is a proc' do
588+
let(:options) { { client: -> { :alternative } } }
589+
590+
it 'evaluates the proc' do
591+
expect(persistence_context.client).to eq(Mongoid::Clients.with_name(:alternative))
592+
end
593+
end
594+
587595
context 'when there is a client override' do
588596
persistence_context_override :client, :other
589597

0 commit comments

Comments
 (0)