Skip to content

Commit d8a0883

Browse files
Add tests for read_preference option
1 parent 8a33fa3 commit d8a0883

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Diff for: spec/integration/find_options_spec.rb

+45
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,49 @@
157157
end
158158
end
159159
end
160+
161+
describe 'read preference' do
162+
require_topology :replica_set
163+
164+
context 'when defined on the client' do
165+
let(:client_options) do
166+
{ read: { mode: :secondary } }
167+
end
168+
169+
let(:collection_options) do
170+
{}
171+
end
172+
173+
it 'uses the read preference defined on the client' do
174+
collection.find.to_a
175+
expect(find_command.command['$readPreference']).to eq('mode' => 'secondary')
176+
end
177+
178+
context 'when defzained on the collection' do
179+
let(:collection_options) do
180+
{ read: { mode: :secondary_preferred } }
181+
end
182+
183+
it 'uses the read concern defined on the collection' do
184+
collection.find.to_a
185+
expect(find_command.command['$readPreference']).to eq('mode' => 'secondaryPreferred')
186+
end
187+
188+
context 'when defined on the operation' do
189+
let(:collection_options) do
190+
{}
191+
end
192+
193+
let(:operation_read_concern) do
194+
{ 'level' => 'available' }
195+
end
196+
197+
it 'uses the read concern defined on the operation' do
198+
collection.find({}, read_concern: operation_read_concern).to_a
199+
expect(find_command.command['readConcern']).to eq(operation_read_concern)
200+
end
201+
end
202+
end
203+
end
204+
end
160205
end

0 commit comments

Comments
 (0)