mongo 2.0.0.beta → 2.0.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Rakefile +14 -1
- data/lib/mongo.rb +2 -1
- data/lib/mongo/auth.rb +2 -2
- data/lib/mongo/bulk_write.rb +52 -0
- data/lib/mongo/bulk_write/bulk_writable.rb +191 -0
- data/lib/mongo/bulk_write/deletable.rb +60 -0
- data/lib/mongo/bulk_write/insertable.rb +52 -0
- data/lib/mongo/bulk_write/ordered_bulk_write.rb +48 -0
- data/lib/mongo/bulk_write/replacable.rb +57 -0
- data/lib/mongo/bulk_write/unordered_bulk_write.rb +46 -0
- data/lib/mongo/bulk_write/updatable.rb +68 -0
- data/lib/mongo/client.rb +15 -2
- data/lib/mongo/cluster/topology/replica_set.rb +1 -1
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/cluster/topology/standalone.rb +1 -1
- data/lib/mongo/cluster/topology/unknown.rb +1 -1
- data/lib/mongo/collection.rb +1 -1
- data/lib/mongo/collection/view/aggregation.rb +1 -1
- data/lib/mongo/collection/view/readable.rb +1 -1
- data/lib/mongo/collection/view/writable.rb +5 -5
- data/lib/mongo/cursor.rb +0 -2
- data/lib/mongo/error.rb +4 -3
- data/lib/mongo/error/{bulk_write_failure.rb → bulk_write_error.rb} +2 -2
- data/lib/mongo/error/invalid_bulk_operation.rb +2 -2
- data/lib/mongo/error/invalid_bulk_operation_type.rb +36 -0
- data/lib/mongo/error/{empty_batch.rb → multi_index_drop.rb} +5 -10
- data/lib/mongo/grid/file/metadata.rb +1 -8
- data/lib/mongo/grid/fs.rb +5 -5
- data/lib/mongo/index/view.rb +90 -34
- data/lib/mongo/operation.rb +0 -1
- data/lib/mongo/operation/aggregate.rb +2 -2
- data/lib/mongo/operation/aggregate/result.rb +4 -0
- data/lib/mongo/operation/bulk_delete/result.rb +2 -127
- data/lib/mongo/operation/bulk_insert/result.rb +2 -132
- data/lib/mongo/operation/bulk_update/result.rb +2 -142
- data/lib/mongo/operation/command.rb +1 -1
- data/lib/mongo/operation/executable.rb +3 -3
- data/lib/mongo/operation/list_collections/result.rb +0 -2
- data/lib/mongo/operation/map_reduce.rb +1 -1
- data/lib/mongo/operation/read/collections_info.rb +1 -1
- data/lib/mongo/operation/read/get_more.rb +1 -1
- data/lib/mongo/operation/read/indexes.rb +1 -1
- data/lib/mongo/operation/read/list_collections.rb +1 -1
- data/lib/mongo/operation/read/list_indexes.rb +1 -1
- data/lib/mongo/operation/read/query.rb +1 -1
- data/lib/mongo/operation/specifiable.rb +18 -1
- data/lib/mongo/operation/write.rb +2 -0
- data/lib/mongo/operation/write/bulk_delete.rb +5 -19
- data/lib/mongo/operation/write/bulk_insert.rb +9 -40
- data/lib/mongo/operation/write/bulk_mergable.rb +67 -0
- data/lib/mongo/operation/write/bulk_update.rb +5 -19
- data/lib/mongo/operation/write/command.rb +1 -1
- data/lib/mongo/operation/write/command/{ensure_index.rb → create_index.rb} +4 -9
- data/lib/mongo/operation/write/command/delete.rb +4 -4
- data/lib/mongo/operation/write/command/drop_index.rb +1 -1
- data/lib/mongo/operation/write/command/insert.rb +4 -4
- data/lib/mongo/operation/write/command/update.rb +4 -4
- data/lib/mongo/operation/write/create_index.rb +12 -7
- data/lib/mongo/operation/write/create_user.rb +1 -1
- data/lib/mongo/operation/write/delete.rb +1 -1
- data/lib/mongo/operation/write/drop_index.rb +1 -1
- data/lib/mongo/operation/write/insert.rb +1 -1
- data/lib/mongo/operation/write/legacy_bulk_mergable.rb +83 -0
- data/lib/mongo/operation/write/remove_user.rb +1 -1
- data/lib/mongo/operation/write/update.rb +1 -1
- data/lib/mongo/{bulk.rb → options.rb} +2 -2
- data/lib/mongo/options/mapper.rb +78 -0
- data/lib/mongo/server.rb +2 -2
- data/lib/mongo/server/connection_pool/queue.rb +1 -1
- data/lib/mongo/server/description.rb +1 -1
- data/lib/mongo/server/description/inspector.rb +1 -1
- data/lib/mongo/server_selector.rb +1 -1
- data/lib/mongo/socket/unix.rb +2 -4
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern/acknowledged.rb +15 -1
- data/lib/mongo/write_concern/normalizable.rb +0 -22
- data/lib/mongo/write_concern/unacknowledged.rb +12 -0
- data/spec/mongo/bulk/bulk_write_spec.rb +178 -91
- data/spec/mongo/collection/view/aggregation_spec.rb +14 -1
- data/spec/mongo/collection/view/explainable_spec.rb +1 -1
- data/spec/mongo/collection/view/map_reduce_spec.rb +2 -2
- data/spec/mongo/collection/view/readable_spec.rb +2 -2
- data/spec/mongo/collection/view/writable_spec.rb +7 -7
- data/spec/mongo/collection/view_spec.rb +14 -5
- data/spec/mongo/collection_spec.rb +5 -5
- data/spec/mongo/cursor_spec.rb +3 -3
- data/spec/mongo/database_spec.rb +4 -8
- data/spec/mongo/grid/fs_spec.rb +8 -8
- data/spec/mongo/index/view_spec.rb +139 -35
- data/spec/mongo/operation/aggregate_spec.rb +14 -22
- data/spec/mongo/operation/command_spec.rb +8 -16
- data/spec/mongo/operation/map_reduce_spec.rb +1 -1
- data/spec/mongo/operation/read/indexes_spec.rb +2 -2
- data/spec/mongo/operation/write/bulk_delete_spec.rb +1 -239
- data/spec/mongo/operation/write/bulk_insert_spec.rb +3 -234
- data/spec/mongo/operation/write/bulk_update_spec.rb +1 -289
- data/spec/mongo/operation/write/command/delete_spec.rb +0 -13
- data/spec/mongo/operation/write/command/insert_spec.rb +0 -14
- data/spec/mongo/operation/write/command/update_spec.rb +0 -14
- data/spec/mongo/operation/write/{ensure_index_spec.rb → create_index_spec.rb} +8 -26
- data/spec/mongo/operation/write/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/drop_index_spec.rb +1 -1
- data/spec/mongo/operation/write/insert_spec.rb +3 -3
- data/spec/mongo/operation/write/update_spec.rb +1 -1
- data/spec/mongo/server_selection_spec.rb +2 -2
- data/spec/support/authorization.rb +4 -2
- data/spec/support/server_selection.rb +25 -8
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest.yml +4 -10
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_non_matching.yml +6 -12
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Primary.yml +4 -6
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred.yml +4 -10
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred_non_matching.yml +6 -12
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary.yml +4 -10
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred.yml +4 -10
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred_non_matching.yml +6 -12
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_non_matching.yml +6 -12
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest.yml +9 -17
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_non_matching.yml +9 -17
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Primary.yml +6 -10
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred.yml +11 -21
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred_non_matching.yml +11 -18
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary.yml +31 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred.yml +31 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_non_matching.yml +29 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary_non_matching.yml +26 -0
- data/spec/support/server_selection/selection/Sharded/read/SecondaryPreferred.yml +4 -10
- data/spec/support/server_selection/selection/Single/read/SecondaryPreferred.yml +2 -6
- data/spec/support/server_selection/selection/Unknown/read/SecondaryPreferred.yml +0 -2
- data/spec/support/shared/bulk_write.rb +109 -72
- metadata +29 -10
- metadata.gz.sig +0 -0
- data/lib/mongo/bulk/bulk_write.rb +0 -307
- data/lib/mongo/operation/batchable.rb +0 -103
@@ -83,263 +83,6 @@ describe Mongo::Operation::Write::BulkUpdate do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
describe '#write_concern' do
|
87
|
-
|
88
|
-
let(:other_write_concern) do
|
89
|
-
{ w: 2 }
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'when the write concern is set' do
|
93
|
-
|
94
|
-
it 'sets the write concern' do
|
95
|
-
new_op = op.write_concern(other_write_concern)
|
96
|
-
expect(new_op.write_concern.options).to eq(other_write_concern)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe '#batch' do
|
102
|
-
|
103
|
-
context 'when number of updates is evenly divisible by number of batches' do
|
104
|
-
let(:documents) do
|
105
|
-
[{ q: { a: 1 },
|
106
|
-
u: { :$set => { a: 2 } },
|
107
|
-
multi: true,
|
108
|
-
upsert: false },
|
109
|
-
{ q: { b: 1 },
|
110
|
-
u: { :$set => { b: 2 } },
|
111
|
-
multi: true,
|
112
|
-
upsert: false },
|
113
|
-
{ q: { c: 1 },
|
114
|
-
u: { :$set => { c: 2 } },
|
115
|
-
multi: true,
|
116
|
-
upsert: false },
|
117
|
-
{ q: { d: 1 },
|
118
|
-
u: { :$set => { d: 2 } },
|
119
|
-
multi: true,
|
120
|
-
upsert: false },
|
121
|
-
{ q: { e: 1 },
|
122
|
-
u: { :$set => { e: 2 } },
|
123
|
-
multi: true,
|
124
|
-
upsert: false },
|
125
|
-
{ q: { f: 1 },
|
126
|
-
u: { :$set => { f: 2 } },
|
127
|
-
multi: true,
|
128
|
-
upsert: false }
|
129
|
-
]
|
130
|
-
end
|
131
|
-
|
132
|
-
let(:n_batches) { 3 }
|
133
|
-
|
134
|
-
it 'splits the op into the n_batches number of children ops' do
|
135
|
-
expect(op.batch(n_batches).size).to eq(n_batches)
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'divides the updates evenly between children ops' do
|
139
|
-
ops = op.batch(n_batches)
|
140
|
-
batch_size = documents.size / n_batches
|
141
|
-
|
142
|
-
n_batches.times do |i|
|
143
|
-
start_index = i * batch_size
|
144
|
-
expect(ops[i].spec[:updates]).to eq(documents[start_index, batch_size])
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context 'when number of updates is less than number of batches' do
|
150
|
-
let(:documents) do
|
151
|
-
[ { q: { a: 1 },
|
152
|
-
u: { :$set => { a: 2 } } } ]
|
153
|
-
end
|
154
|
-
let(:n_batches) { 3 }
|
155
|
-
|
156
|
-
it 'raises an exception' do
|
157
|
-
expect {
|
158
|
-
op.batch(n_batches)
|
159
|
-
}.to raise_error(Exception)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
context 'when number of updates is not evenly divisible by number of batches' do
|
164
|
-
let(:documents) do
|
165
|
-
[{ q: { a: 1 },
|
166
|
-
u: { :$set => { a: 2 } },
|
167
|
-
multi: true,
|
168
|
-
upsert: false },
|
169
|
-
{ q: { b: 1 },
|
170
|
-
u: { :$set => { b: 2 } },
|
171
|
-
multi: true,
|
172
|
-
upsert: false },
|
173
|
-
{ q: { c: 1 },
|
174
|
-
u: { :$set => { c: 2 } },
|
175
|
-
multi: true,
|
176
|
-
upsert: false },
|
177
|
-
{ q: { d: 1 },
|
178
|
-
u: { :$set => { d: 2 } },
|
179
|
-
multi: true,
|
180
|
-
upsert: false },
|
181
|
-
{ q: { e: 1 },
|
182
|
-
u: { :$set => { e: 2 } },
|
183
|
-
multi: true,
|
184
|
-
upsert: false },
|
185
|
-
{ q: { f: 1 },
|
186
|
-
u: { :$set => { f: 2 } },
|
187
|
-
multi: true,
|
188
|
-
upsert: false }
|
189
|
-
]
|
190
|
-
end
|
191
|
-
let(:n_batches) { 4 }
|
192
|
-
|
193
|
-
it 'splits the op into the n_batches number of children ops' do
|
194
|
-
expect(op.batch(n_batches).size).to eq(n_batches)
|
195
|
-
end
|
196
|
-
|
197
|
-
it 'divides the updates evenly between children ops' do
|
198
|
-
ops = op.batch(n_batches)
|
199
|
-
batch_size = documents.size / n_batches
|
200
|
-
|
201
|
-
n_batches.times do |i|
|
202
|
-
start_index = i * batch_size
|
203
|
-
if i == n_batches - 1
|
204
|
-
expect(ops[i].spec[:updates]).to eq(documents[start_index..-1])
|
205
|
-
else
|
206
|
-
expect(ops[i].spec[:updates]).to eq(documents[start_index, batch_size])
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
describe '#merge!' do
|
214
|
-
|
215
|
-
context 'same collection and database' do
|
216
|
-
|
217
|
-
let(:other_docs) do
|
218
|
-
[ { q: { foo: 1 },
|
219
|
-
u: { :$set => { bar: 1 } },
|
220
|
-
multi: true,
|
221
|
-
upsert: true } ]
|
222
|
-
end
|
223
|
-
|
224
|
-
let(:other_spec) do
|
225
|
-
{ updates: other_docs,
|
226
|
-
db_name: db_name,
|
227
|
-
coll_name: coll_name
|
228
|
-
}
|
229
|
-
end
|
230
|
-
|
231
|
-
let(:other) { described_class.new(other_spec) }
|
232
|
-
|
233
|
-
it 'merges the two ops' do
|
234
|
-
expect{ op.merge!(other) }.not_to raise_exception
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
context 'different database' do
|
239
|
-
|
240
|
-
let(:other_docs) do
|
241
|
-
[ { q: { :foo => 1 },
|
242
|
-
u: { :$set => { bar: 1 } },
|
243
|
-
multi: true,
|
244
|
-
upsert: true } ]
|
245
|
-
end
|
246
|
-
|
247
|
-
let(:other_spec) do
|
248
|
-
{ updates: other_docs,
|
249
|
-
db_name: 'different',
|
250
|
-
coll_name: coll_name
|
251
|
-
}
|
252
|
-
end
|
253
|
-
|
254
|
-
let(:other) { described_class.new(other_spec) }
|
255
|
-
|
256
|
-
it 'raises an exception' do
|
257
|
-
expect{ op.merge!(other) }.to raise_exception
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
context 'different collection' do
|
262
|
-
|
263
|
-
let(:other_docs) do
|
264
|
-
[ { q: { foo: 1 },
|
265
|
-
u: { :$set => { bar: 1 } },
|
266
|
-
multi: true,
|
267
|
-
upsert: true } ]
|
268
|
-
end
|
269
|
-
|
270
|
-
let(:other_spec) do
|
271
|
-
{ updates: other_docs,
|
272
|
-
db_name: db_name,
|
273
|
-
coll_name: 'different'
|
274
|
-
}
|
275
|
-
end
|
276
|
-
|
277
|
-
let(:other) { described_class.new(other_spec) }
|
278
|
-
|
279
|
-
it 'raises an exception' do
|
280
|
-
expect{ op.merge!(other) }.to raise_exception
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
context 'different operation type' do
|
285
|
-
let(:other) { Mongo::Write::Insert.new(spec) }
|
286
|
-
|
287
|
-
it 'raises an exception' do
|
288
|
-
expect{ op.merge!(other) }.to raise_exception
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
context 'merged updates' do
|
293
|
-
|
294
|
-
let(:other_docs) do
|
295
|
-
[ { q: { foo: 1 },
|
296
|
-
u: { :$set => { bar: 1 } },
|
297
|
-
multi: true,
|
298
|
-
upsert: true } ]
|
299
|
-
end
|
300
|
-
|
301
|
-
let(:other_spec) do
|
302
|
-
{ updates: other_docs,
|
303
|
-
db_name: db_name,
|
304
|
-
coll_name: coll_name
|
305
|
-
}
|
306
|
-
end
|
307
|
-
|
308
|
-
let(:other) { described_class.new(other_spec) }
|
309
|
-
|
310
|
-
let(:expected) do
|
311
|
-
documents + other_docs
|
312
|
-
end
|
313
|
-
|
314
|
-
it 'merges the list of updates' do
|
315
|
-
expect(op.merge!(other).spec[:updates]).to eq(expected)
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
context 'mutability' do
|
320
|
-
|
321
|
-
let(:other_docs) do
|
322
|
-
[ { q: { foo: 1 },
|
323
|
-
u: { :$set => { bar: 1 } },
|
324
|
-
multi: true,
|
325
|
-
upsert: true } ]
|
326
|
-
end
|
327
|
-
|
328
|
-
let(:other_spec) do
|
329
|
-
{ updates: other_docs,
|
330
|
-
db_name: db_name,
|
331
|
-
coll_name: coll_name
|
332
|
-
}
|
333
|
-
end
|
334
|
-
|
335
|
-
let(:other) { described_class.new(other_spec) }
|
336
|
-
|
337
|
-
it 'mutates the operation itself' do
|
338
|
-
expect(op.merge!(other)).to be(op)
|
339
|
-
end
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
86
|
describe '#execute' do
|
344
87
|
|
345
88
|
before do
|
@@ -350,7 +93,7 @@ describe Mongo::Operation::Write::BulkUpdate do
|
|
350
93
|
end
|
351
94
|
|
352
95
|
after do
|
353
|
-
authorized_collection.find.
|
96
|
+
authorized_collection.find.delete_many
|
354
97
|
end
|
355
98
|
|
356
99
|
context 'when updating a single document' do
|
@@ -489,36 +232,5 @@ describe Mongo::Operation::Write::BulkUpdate do
|
|
489
232
|
end
|
490
233
|
end
|
491
234
|
end
|
492
|
-
|
493
|
-
context 'when a write concern override is specified' do
|
494
|
-
|
495
|
-
let(:op) do
|
496
|
-
described_class.new({
|
497
|
-
updates: documents,
|
498
|
-
db_name: db_name,
|
499
|
-
coll_name: coll_name,
|
500
|
-
write_concern: Mongo::WriteConcern.get(w: 1),
|
501
|
-
ordered: false
|
502
|
-
})
|
503
|
-
end
|
504
|
-
|
505
|
-
let(:documents) do
|
506
|
-
[ { q: { name: 'test' }, u: { '$st' => { field: 'blah' }}, multi: true} ]
|
507
|
-
end
|
508
|
-
|
509
|
-
let(:unacknowledged) do
|
510
|
-
{ w: 0 }
|
511
|
-
end
|
512
|
-
|
513
|
-
it 'uses that write concern', if: write_command_enabled? do
|
514
|
-
result = op.write_concern(unacknowledged).execute(authorized_primary.context)
|
515
|
-
expect(result.replies.size).to eq(1)
|
516
|
-
end
|
517
|
-
|
518
|
-
it 'uses that write concern', unless: write_command_enabled? do
|
519
|
-
result = op.write_concern(unacknowledged).execute(authorized_primary.context)
|
520
|
-
expect(result.replies).to be(nil)
|
521
|
-
end
|
522
|
-
end
|
523
235
|
end
|
524
236
|
end
|
@@ -98,19 +98,6 @@ describe Mongo::Operation::Write::Command::Delete do
|
|
98
98
|
op.execute(primary_context)
|
99
99
|
end
|
100
100
|
end
|
101
|
-
|
102
|
-
context 'write concern' do
|
103
|
-
|
104
|
-
context 'w == 0' do
|
105
|
-
|
106
|
-
pending 'no response is returned'
|
107
|
-
end
|
108
|
-
|
109
|
-
context 'w > 0' do
|
110
|
-
|
111
|
-
pending 'returns a response'
|
112
|
-
end
|
113
|
-
end
|
114
101
|
end
|
115
102
|
end
|
116
103
|
end
|
@@ -98,20 +98,6 @@ describe Mongo::Operation::Write::Command::Insert do
|
|
98
98
|
op.execute(primary_context)
|
99
99
|
end
|
100
100
|
end
|
101
|
-
|
102
|
-
context 'write concern' do
|
103
|
-
|
104
|
-
context 'w == 0' do
|
105
|
-
|
106
|
-
pending 'no response is returned'
|
107
|
-
end
|
108
|
-
|
109
|
-
context 'w > 0' do
|
110
|
-
|
111
|
-
pending 'returns a response'
|
112
|
-
end
|
113
|
-
end
|
114
101
|
end
|
115
102
|
end
|
116
103
|
end
|
117
|
-
|
@@ -104,20 +104,6 @@ describe Mongo::Operation::Write::Command::Update do
|
|
104
104
|
op.execute(primary_context)
|
105
105
|
end
|
106
106
|
end
|
107
|
-
|
108
|
-
context 'write concern' do
|
109
|
-
|
110
|
-
context 'w == 0' do
|
111
|
-
|
112
|
-
pending 'no response is returned'
|
113
|
-
end
|
114
|
-
|
115
|
-
context 'w > 0' do
|
116
|
-
|
117
|
-
pending 'returns a response'
|
118
|
-
end
|
119
|
-
end
|
120
107
|
end
|
121
108
|
end
|
122
109
|
end
|
123
|
-
|
@@ -1,23 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Mongo::Operation::Write::
|
3
|
+
describe Mongo::Operation::Write::CreateIndex do
|
4
4
|
|
5
5
|
describe '#execute' do
|
6
6
|
|
7
7
|
context 'when the index is created' do
|
8
8
|
|
9
9
|
let(:spec) do
|
10
|
-
{ random: 1 }
|
10
|
+
{ key: { random: 1 }, name: 'random_1', unique: true }
|
11
11
|
end
|
12
12
|
|
13
13
|
let(:operation) do
|
14
|
-
described_class.new(
|
15
|
-
index: spec,
|
16
|
-
db_name: TEST_DB,
|
17
|
-
coll_name: TEST_COLL,
|
18
|
-
index_name: 'random_1',
|
19
|
-
options: { unique: true }
|
20
|
-
)
|
14
|
+
described_class.new(indexes: [ spec ], db_name: TEST_DB, coll_name: TEST_COLL)
|
21
15
|
end
|
22
16
|
|
23
17
|
let(:response) do
|
@@ -25,7 +19,7 @@ describe Mongo::Operation::Write::EnsureIndex do
|
|
25
19
|
end
|
26
20
|
|
27
21
|
after do
|
28
|
-
authorized_collection.indexes.
|
22
|
+
authorized_collection.indexes.drop_one('random_1')
|
29
23
|
end
|
30
24
|
|
31
25
|
it 'returns ok' do
|
@@ -36,27 +30,15 @@ describe Mongo::Operation::Write::EnsureIndex do
|
|
36
30
|
context 'when index creation fails' do
|
37
31
|
|
38
32
|
let(:spec) do
|
39
|
-
{ random: 1 }
|
33
|
+
{ key: { random: 1 }, name: 'random_1', unique: true }
|
40
34
|
end
|
41
35
|
|
42
36
|
let(:operation) do
|
43
|
-
described_class.new(
|
44
|
-
index: spec,
|
45
|
-
db_name: TEST_DB,
|
46
|
-
coll_name: TEST_COLL,
|
47
|
-
index_name: 'random_1',
|
48
|
-
options: { unique: true }
|
49
|
-
)
|
37
|
+
described_class.new(indexes: [ spec ], db_name: TEST_DB, coll_name: TEST_COLL)
|
50
38
|
end
|
51
39
|
|
52
40
|
let(:second_operation) do
|
53
|
-
described_class.new(
|
54
|
-
index: spec,
|
55
|
-
db_name: TEST_DB,
|
56
|
-
coll_name: TEST_COLL,
|
57
|
-
index_name: 'random_1',
|
58
|
-
options: { unique: false }
|
59
|
-
)
|
41
|
+
described_class.new(indexes: [ spec.merge(unique: false) ], db_name: TEST_DB, coll_name: TEST_COLL)
|
60
42
|
end
|
61
43
|
|
62
44
|
before do
|
@@ -64,7 +46,7 @@ describe Mongo::Operation::Write::EnsureIndex do
|
|
64
46
|
end
|
65
47
|
|
66
48
|
after do
|
67
|
-
authorized_collection.indexes.
|
49
|
+
authorized_collection.indexes.drop_one('random_1')
|
68
50
|
end
|
69
51
|
|
70
52
|
it 'raises an exception', if: write_command_enabled? do
|