Skip to content

Commit 8a33fa3

Browse files
Add tests for read_concern option
1 parent 1a3f710 commit 8a33fa3

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

spec/integration/find_options_spec.rb

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,88 @@
7373
end
7474
end
7575
end
76+
77+
describe 'read concern' do
78+
let(:read_concern) do
79+
{ 'level' => 'local' }
80+
end
81+
82+
context 'when defined on the client' do
83+
let(:client_options) do
84+
{ read_concern: read_concern }
85+
end
86+
87+
let(:collection_options) do
88+
{}
89+
end
90+
91+
it 'uses the read concern defined on the client' do
92+
collection.find.to_a
93+
expect(find_command.command['readConcern']).to eq(read_concern)
94+
end
95+
96+
context 'when defined on the collection' do
97+
let(:collection_options) do
98+
{ read_concern: { 'level' => 'majority' } }
99+
end
100+
101+
it 'uses the read concern defined on the collection' do
102+
collection.find.to_a
103+
expect(find_command.command['readConcern']).to eq(collection_options[:read_concern])
104+
end
105+
106+
context 'when defined on the operation' do
107+
let(:operation_read_concern) do
108+
{ 'level' => 'available' }
109+
end
110+
111+
it 'uses the read concern defined on the operation' do
112+
collection.find({}, read_concern: operation_read_concern).to_a
113+
expect(find_command.command['readConcern']).to eq(operation_read_concern)
114+
end
115+
end
116+
end
117+
118+
context 'when defined on the operation' do
119+
let(:collection_options) do
120+
{}
121+
end
122+
123+
let(:operation_read_concern) do
124+
{ 'level' => 'available' }
125+
end
126+
127+
it 'uses the read concern defined on the operation' do
128+
collection.find({}, read_concern: operation_read_concern).to_a
129+
expect(find_command.command['readConcern']).to eq(operation_read_concern)
130+
end
131+
end
132+
end
133+
134+
context 'when defined on the collection' do
135+
let(:client_options) do
136+
{}
137+
end
138+
139+
let(:collection_options) do
140+
{ read_concern: { 'level' => 'majority' } }
141+
end
142+
143+
it 'uses the read concern defined on the collection' do
144+
collection.find.to_a
145+
expect(find_command.command['readConcern']).to eq(collection_options[:read_concern])
146+
end
147+
148+
context 'when defined on the operation' do
149+
let(:operation_read_concern) do
150+
{ 'level' => 'available' }
151+
end
152+
153+
it 'uses the read concern defined on the operation' do
154+
collection.find({}, read_concern: operation_read_concern).to_a
155+
expect(find_command.command['readConcern']).to eq(operation_read_concern)
156+
end
157+
end
158+
end
159+
end
76160
end

0 commit comments

Comments
 (0)