File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -148,8 +148,8 @@ def collections
148
148
#
149
149
# @return [ Hash ] The result of the command execution.
150
150
def command ( operation , opts = { } )
151
- preference = opts [ :read ] ? ServerSelector . get ( client . options . merge ( opts [ :read ] ) ) : read_preference
152
- server = preference . select_server ( cluster )
151
+ preference = ServerSelector . get ( client . options . merge ( opts [ :read ] ) ) if opts [ :read ]
152
+ server = preference ? preference . select_server ( cluster ) : cluster . next_primary
153
153
Operation ::Command . new ( {
154
154
:selector => operation ,
155
155
:db_name => name ,
Original file line number Diff line number Diff line change 228
228
end . to raise_error ( Mongo ::Error ::NoServerAvailable )
229
229
end
230
230
end
231
+
232
+ context 'when there is a read preference set on the client' do
233
+
234
+ let ( :database ) do
235
+ described_class . new ( authorized_client . with ( read : { mode : :secondary } ) , TEST_DB )
236
+ end
237
+
238
+ it 'does not use the read preference' do
239
+ expect ( database . client . cluster ) . to receive ( :next_primary ) . and_call_original
240
+ database . command ( ping : 1 )
241
+ end
242
+ end
231
243
end
232
244
233
245
describe '#drop' do
You can’t perform that action at this time.
0 commit comments