Skip to content

Commit 856dd2a

Browse files
committed
Update CRUD yaml test runner
1 parent 3c4e729 commit 856dd2a

File tree

3 files changed

+36
-38
lines changed

3 files changed

+36
-38
lines changed

lib/mongo/collection/view/aggregation.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class Aggregation
4242
# @since 2.1.0
4343
OPTIONS_MAP = {
4444
:allow_disk_use => :allowDiskUse,
45-
:max_time_ms => :maxTimeMS,
46-
:batch_size => :batchSize
45+
:max_time_ms => :maxTimeMS
4746
}
4847

4948
# Set to true if disk usage is allowed during the aggregation.
@@ -105,11 +104,7 @@ def aggregate_spec
105104

106105
def process_options
107106
@agg_options ||= @options.each.reduce({}) do |opts, (key, value)|
108-
if OPTIONS_MAP[key]
109-
opts.merge(OPTIONS_MAP[key] => value)
110-
else
111-
opts.merge(key => value)
112-
end
107+
OPTIONS_MAP[key] ? opts.merge(OPTIONS_MAP[key] => value) : opts
113108
end
114109
end
115110

@@ -121,7 +116,7 @@ def cursor
121116

122117
def batch_size_doc
123118
(value = options[:batch_size] || view.batch_size) ?
124-
{ OPTIONS_MAP[:batch_size] => value } : {}
119+
{ :batchSize => value } : {}
125120
end
126121

127122
def explain_options

spec/support/crud/read.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,30 +93,29 @@ def requires_2_6?(collection)
9393
private
9494

9595
def count(collection)
96-
view = collection.find(filter)
9796
options = ARGUMENT_MAP.reduce({}) do |opts, (key, value)|
9897
opts.merge!(key => arguments[value]) if arguments[value]
9998
opts
10099
end
101-
view.count(options)
100+
collection.count(filter, options)
102101
end
103102

104103
def aggregate(collection)
105-
collection.find.tap do |view|
106-
view = view.batch_size(batch_size) if batch_size
107-
end.aggregate(pipeline).to_a
104+
collection.aggregate(pipeline, options).to_a
108105
end
109106

110107
def distinct(collection)
111-
collection.find(filter).distinct(field_name)
108+
collection.distinct(field_name, filter)
112109
end
113110

114111
def find(collection)
115-
view = collection.find(filter)
116-
ARGUMENT_MAP.each do |key, value|
117-
view = view.send(key, arguments[value]) if arguments[value]
112+
collection.find(filter, options).to_a
113+
end
114+
115+
def options
116+
ARGUMENT_MAP.reduce({}) do |opts, (key, value)|
117+
arguments[value] ? opts.merge!(key => arguments[value]) : opts
118118
end
119-
view.to_a
120119
end
121120

122121
def batch_size

spec/support/crud/write.rb

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ class Write
4242
# @since 2.0.0
4343
ARGUMENT_MAP = {
4444
:sort => 'sort',
45-
:projection => 'projection'
45+
:projection => 'projection',
46+
:return_document => 'returnDocument',
47+
:upsert => 'upsert'
4648
}
4749

4850
# Operations that need a check if results on < 2.6 will match.
@@ -111,12 +113,12 @@ def requires_2_6?(collection)
111113
private
112114

113115
def delete_many(collection)
114-
result = collection.find(filter).delete_many
116+
result = collection.delete_many(filter)
115117
{ 'deletedCount' => result.deleted_count }
116118
end
117119

118120
def delete_one(collection)
119-
result = collection.find(filter).delete_one
121+
result = collection.delete_one(filter)
120122
{ 'deletedCount' => result.deleted_count }
121123
end
122124

@@ -137,48 +139,50 @@ def update_return_doc(result)
137139
end
138140

139141
def replace_one(collection)
140-
result = collection.find(filter).replace_one(replacement, upsert: upsert)
142+
result = collection.replace_one(filter, replacement, options)
141143
update_return_doc(result)
142144
end
143145

144146
def update_many(collection)
145-
result = collection.find(filter).update_many(update, upsert: upsert)
147+
result = collection.update_many(filter, update, options)
146148
update_return_doc(result)
147149
end
148150

149151
def update_one(collection)
150-
result = collection.find(filter).update_one(update, upsert: upsert)
152+
result = collection.update_one(filter, update, options)
151153
update_return_doc(result)
152154
end
153155

154156
def find_one_and_delete(collection)
155-
view = collection.find(filter)
156-
ARGUMENT_MAP.each do |key, value|
157-
view = view.send(key, arguments[value]) if arguments[value]
158-
end
159-
view.find_one_and_delete
157+
collection.find_one_and_delete(filter, options)
160158
end
161159

162160
def find_one_and_replace(collection)
163-
view = collection.find(filter)
164-
ARGUMENT_MAP.each do |key, value|
165-
view = view.send(key, arguments[value]) if arguments[value]
166-
end
167-
view.find_one_and_replace(replacement, upsert: upsert, return_document: return_document)
161+
collection.find_one_and_replace(filter, replacement,options)
168162
end
169163

170164
def find_one_and_update(collection)
171-
view = collection.find(filter)
172-
ARGUMENT_MAP.each do |key, value|
173-
view = view.send(key, arguments[value]) if arguments[value]
165+
collection.find_one_and_update(filter, update, options)
166+
end
167+
168+
def options
169+
ARGUMENT_MAP.reduce({}) do |opts, (key, value)|
170+
arguments[value] ? opts.merge!(key => send(key)) : opts
174171
end
175-
view.find_one_and_update(update, upsert: upsert, return_document: return_document)
176172
end
177173

178174
def replacement
179175
arguments['replacement']
180176
end
181177

178+
def sort
179+
arguments['sort']
180+
end
181+
182+
def projection
183+
arguments['projection']
184+
end
185+
182186
def documents
183187
arguments['documents']
184188
end

0 commit comments

Comments
 (0)