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
117
117
def client
118
118
@client ||= begin
119
119
client = Clients . with_name ( client_name )
120
+ options = client_options
121
+
120
122
if database_name_option
121
123
client = client . use ( database_name )
124
+ options = options . except ( :database , 'database' )
122
125
end
123
- unless client_options . empty?
124
- client = client . with ( client_options )
125
- end
126
+
127
+ client = client . with ( options ) unless options . empty?
128
+
126
129
client
127
130
end
128
131
end
Original file line number Diff line number Diff line change 27
27
let ( :options ) { { database : 'other' } }
28
28
29
29
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 )
31
31
end
32
32
33
33
it 'does not set the options on class level' do
319
319
end
320
320
321
321
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 )
323
323
end
324
324
325
325
it 'does not set the options on instance level' do
Original file line number Diff line number Diff line change 536
536
end
537
537
end
538
538
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
539
553
end
540
554
541
555
describe '#client' do
608
622
end
609
623
end
610
624
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
+
611
642
context 'when there is no client option set' do
612
643
613
644
let ( :options ) do
You can’t perform that action at this time.
0 commit comments