File tree Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -117,12 +117,15 @@ def database_name
117117 def client
118118 @client ||= begin
119119 client = Clients . with_name ( client_name )
120+ options = client_options
121+
120122 if database_name_option
121123 client = client . use ( database_name )
124+ options = options . except ( :database , 'database' )
122125 end
123- unless client_options . empty?
124- client = client . with ( client_options )
125- end
126+
127+ client = client . with ( options ) unless options . empty?
128+
126129 client
127130 end
128131 end
Original file line number Diff line number Diff line change 2727 let ( :options ) { { database : 'other' } }
2828
2929 it 'sets the options on the client' do
30- expect ( persistence_context . client . options [ 'database' ] ) . to eq ( options [ :database ] )
30+ expect ( persistence_context . client . options [ 'database' ] . to_s ) . to eq ( options [ :database ] . to_s )
3131 end
3232
3333 it 'does not set the options on class level' do
319319 end
320320
321321 it 'sets the options on the client' do
322- expect ( persistence_context . client . options [ 'database' ] ) . to eq ( options [ :database ] )
322+ expect ( persistence_context . client . options [ 'database' ] . to_s ) . to eq ( options [ :database ] . to_s )
323323 end
324324
325325 it 'does not set the options on instance level' do
Original file line number Diff line number Diff line change 536536 end
537537 end
538538 end
539+
540+ context 'when the database is specified as a proc' do
541+ let ( :options ) { { database : -> { 'other' } } }
542+
543+ after { persistence_context . client . close }
544+
545+ it 'evaluates the proc' do
546+ expect ( persistence_context . database_name ) . to eq ( :other )
547+ end
548+
549+ it 'does not pass the proc to the client' do
550+ expect ( persistence_context . client . database . name ) . to eq ( 'other' )
551+ end
552+ end
539553 end
540554
541555 describe '#client' do
608622 end
609623 end
610624
625+ context 'when the client is set as a proc in the storage options' do
626+ let ( :options ) { { } }
627+
628+ before do
629+ Band . store_in client : -> { :alternative }
630+ end
631+
632+ after do
633+ persistence_context . client . close
634+ Band . store_in client : nil
635+ end
636+
637+ it 'uses the client option' do
638+ expect ( persistence_context . client ) . to eq ( Mongoid ::Clients . with_name ( :alternative ) )
639+ end
640+ end
641+
611642 context 'when there is no client option set' do
612643
613644 let ( :options ) do
You can’t perform that action at this time.
0 commit comments