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
148148 #
149149 # @return [ Hash ] The result of the command execution.
150150 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
153153 Operation ::Command . new ( {
154154 :selector => operation ,
155155 :db_name => name ,
Original file line number Diff line number Diff line change 228228 end . to raise_error ( Mongo ::Error ::NoServerAvailable )
229229 end
230230 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
231243 end
232244
233245 describe '#drop' do
You can’t perform that action at this time.
0 commit comments