Skip to content

Commit 4a1648b

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

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: spec/integration/find_options_spec.rb

+30
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,34 @@
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 defined 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+
end
188+
end
189+
end
160190
end

0 commit comments

Comments
 (0)