Skip to content

Commit

Permalink
make sure to evaluate client name since it might be a proc (#5906) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jamis authored Nov 27, 2024
1 parent fde698f commit 838eea4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongoid/persistence_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def client
# @return [ Symbol ] The client name for this persistence
# context.
def client_name
@client_name ||= options[:client] ||
@client_name ||= __evaluate__(options[:client]) ||
Threaded.client_override ||
__evaluate__(storage_options[:client])
end
Expand Down
8 changes: 8 additions & 0 deletions spec/mongoid/persistence_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,14 @@
expect(persistence_context.client).to eq(Mongoid::Clients.with_name(:alternative))
end

context 'when the client option is a proc' do
let(:options) { { client: -> { :alternative } } }

it 'evaluates the proc' do
expect(persistence_context.client).to eq(Mongoid::Clients.with_name(:alternative))
end
end

context 'when there is a client override' do
persistence_context_override :client, :other

Expand Down

0 comments on commit 838eea4

Please sign in to comment.