Skip to content

Commit 49f0046

Browse files
RUBY-2706 Test find related options (mongodb#2789)
* 2706 * Add unified test for all find options * Add missing options * Clarify collation on collection * Add tests for read_concern option * Add tests for read_preference option
1 parent b1f9faf commit 49f0046

File tree

5 files changed

+363
-40
lines changed

5 files changed

+363
-40
lines changed

lib/mongo/collection.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ def capped?
339339
# inserted or updated documents where the clustered index key value
340340
# matches an existing value in the index.
341341
# - *:name* -- Optional. A name that uniquely identifies the clustered index.
342-
# @option opts [ Hash ] :collation The collation to use.
342+
# @option opts [ Hash ] :collation The collation to use when creating the
343+
# collection. This option will not be sent to the server when calling
344+
# collection methods.
343345
# @option opts [ Hash ] :encrypted_fields Hash describing encrypted fields
344346
# for queryable encryption.
345347
# @option opts [ Integer ] :expire_after Number indicating

lib/mongo/collection/view/iterable.rb

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def initial_query_op(session)
162162
let: options[:let],
163163
limit: limit,
164164
allow_disk_use: options[:allow_disk_use],
165+
allow_partial_results: options[:allow_partial_results],
165166
read: read,
166167
read_concern: options[:read_concern] || read_concern,
167168
batch_size: batch_size,

spec/integration/find_options_spec.rb

+2-39
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,10 @@
1313
[ SpecConfig.instance.addresses.first ]
1414
end
1515

16-
let(:client_options) do
17-
{}
18-
end
19-
20-
let(:collection_options) do
21-
{}
22-
end
23-
2416
let(:client) do
2517
ClientRegistry.instance.new_local_client(
2618
seeds,
27-
SpecConfig.instance.test_options
28-
.merge(database: SpecConfig.instance.test_db)
29-
.merge(client_options)
19+
SpecConfig.instance.test_options.merge(client_options)
3020
).tap do |client|
3121
client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
3222
end
@@ -40,11 +30,8 @@
4030
subscriber.started_events.find { |cmd| cmd.command_name == 'find' }
4131
end
4232

43-
let(:should_create_collection) { true }
44-
4533
before do
46-
client['find_options'].drop
47-
collection.create if should_create_collection
34+
ClientRegistry.instance.global_client('authorized')['find_options'].drop
4835
collection.insert_many([ { a: 1 }, { a: 2 }, { a: 3 } ])
4936
end
5037

@@ -84,8 +71,6 @@
8471
{ 'locale' => 'de_AT' }
8572
end
8673

87-
let(:should_create_collection) { false }
88-
8974
it 'uses the collation defined on the collection' do
9075
collection.find({}, collation: collation).to_a
9176
expect(find_command.command['collation']).to eq(collation)
@@ -202,26 +187,4 @@
202187
end
203188
end
204189
end
205-
206-
describe 'cursor type' do
207-
let(:collection_options) do
208-
{ capped: true, size: 1000 }
209-
end
210-
211-
context 'when cursor type is :tailable' do
212-
it 'sets the cursor type to tailable' do
213-
collection.find({}, cursor_type: :tailable).first
214-
expect(find_command.command['tailable']).to be true
215-
expect(find_command.command['awaitData']).to be_falsey
216-
end
217-
end
218-
219-
context 'when cursor type is :tailable_await' do
220-
it 'sets the cursor type to tailable' do
221-
collection.find({}, cursor_type: :tailable_await).first
222-
expect(find_command.command['tailable']).to be true
223-
expect(find_command.command['awaitData']).to be true
224-
end
225-
end
226-
end
227190
end

spec/runners/unified/crud_operations.rb

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ def get_find_view(op)
3232
if session = args.use('session')
3333
opts[:session] = entities.get(:session, session)
3434
end
35+
if collation = args.use('collation')
36+
opts[:collation] = collation
37+
end
38+
if args.key?('noCursorTimeout')
39+
opts[:no_cursor_timeout] = args.use('noCursorTimeout')
40+
end
41+
if args.key?('oplogReplay')
42+
opts[:oplog_replay] = args.use('oplogReplay')
43+
end
44+
if args.key?('allowPartialResults')
45+
opts[:allow_partial_results] = args.use('allowPartialResults')
46+
end
3547
req = collection.find(args.use!('filter'), **opts)
3648
if batch_size = args.use('batchSize')
3749
req = req.batch_size(batch_size)

0 commit comments

Comments
 (0)