mongo 2.0.0.beta → 2.0.0.rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +14 -1
  5. data/lib/mongo.rb +2 -1
  6. data/lib/mongo/auth.rb +2 -2
  7. data/lib/mongo/bulk_write.rb +52 -0
  8. data/lib/mongo/bulk_write/bulk_writable.rb +191 -0
  9. data/lib/mongo/bulk_write/deletable.rb +60 -0
  10. data/lib/mongo/bulk_write/insertable.rb +52 -0
  11. data/lib/mongo/bulk_write/ordered_bulk_write.rb +48 -0
  12. data/lib/mongo/bulk_write/replacable.rb +57 -0
  13. data/lib/mongo/bulk_write/unordered_bulk_write.rb +46 -0
  14. data/lib/mongo/bulk_write/updatable.rb +68 -0
  15. data/lib/mongo/client.rb +15 -2
  16. data/lib/mongo/cluster/topology/replica_set.rb +1 -1
  17. data/lib/mongo/cluster/topology/sharded.rb +1 -1
  18. data/lib/mongo/cluster/topology/standalone.rb +1 -1
  19. data/lib/mongo/cluster/topology/unknown.rb +1 -1
  20. data/lib/mongo/collection.rb +1 -1
  21. data/lib/mongo/collection/view/aggregation.rb +1 -1
  22. data/lib/mongo/collection/view/readable.rb +1 -1
  23. data/lib/mongo/collection/view/writable.rb +5 -5
  24. data/lib/mongo/cursor.rb +0 -2
  25. data/lib/mongo/error.rb +4 -3
  26. data/lib/mongo/error/{bulk_write_failure.rb → bulk_write_error.rb} +2 -2
  27. data/lib/mongo/error/invalid_bulk_operation.rb +2 -2
  28. data/lib/mongo/error/invalid_bulk_operation_type.rb +36 -0
  29. data/lib/mongo/error/{empty_batch.rb → multi_index_drop.rb} +5 -10
  30. data/lib/mongo/grid/file/metadata.rb +1 -8
  31. data/lib/mongo/grid/fs.rb +5 -5
  32. data/lib/mongo/index/view.rb +90 -34
  33. data/lib/mongo/operation.rb +0 -1
  34. data/lib/mongo/operation/aggregate.rb +2 -2
  35. data/lib/mongo/operation/aggregate/result.rb +4 -0
  36. data/lib/mongo/operation/bulk_delete/result.rb +2 -127
  37. data/lib/mongo/operation/bulk_insert/result.rb +2 -132
  38. data/lib/mongo/operation/bulk_update/result.rb +2 -142
  39. data/lib/mongo/operation/command.rb +1 -1
  40. data/lib/mongo/operation/executable.rb +3 -3
  41. data/lib/mongo/operation/list_collections/result.rb +0 -2
  42. data/lib/mongo/operation/map_reduce.rb +1 -1
  43. data/lib/mongo/operation/read/collections_info.rb +1 -1
  44. data/lib/mongo/operation/read/get_more.rb +1 -1
  45. data/lib/mongo/operation/read/indexes.rb +1 -1
  46. data/lib/mongo/operation/read/list_collections.rb +1 -1
  47. data/lib/mongo/operation/read/list_indexes.rb +1 -1
  48. data/lib/mongo/operation/read/query.rb +1 -1
  49. data/lib/mongo/operation/specifiable.rb +18 -1
  50. data/lib/mongo/operation/write.rb +2 -0
  51. data/lib/mongo/operation/write/bulk_delete.rb +5 -19
  52. data/lib/mongo/operation/write/bulk_insert.rb +9 -40
  53. data/lib/mongo/operation/write/bulk_mergable.rb +67 -0
  54. data/lib/mongo/operation/write/bulk_update.rb +5 -19
  55. data/lib/mongo/operation/write/command.rb +1 -1
  56. data/lib/mongo/operation/write/command/{ensure_index.rb → create_index.rb} +4 -9
  57. data/lib/mongo/operation/write/command/delete.rb +4 -4
  58. data/lib/mongo/operation/write/command/drop_index.rb +1 -1
  59. data/lib/mongo/operation/write/command/insert.rb +4 -4
  60. data/lib/mongo/operation/write/command/update.rb +4 -4
  61. data/lib/mongo/operation/write/create_index.rb +12 -7
  62. data/lib/mongo/operation/write/create_user.rb +1 -1
  63. data/lib/mongo/operation/write/delete.rb +1 -1
  64. data/lib/mongo/operation/write/drop_index.rb +1 -1
  65. data/lib/mongo/operation/write/insert.rb +1 -1
  66. data/lib/mongo/operation/write/legacy_bulk_mergable.rb +83 -0
  67. data/lib/mongo/operation/write/remove_user.rb +1 -1
  68. data/lib/mongo/operation/write/update.rb +1 -1
  69. data/lib/mongo/{bulk.rb → options.rb} +2 -2
  70. data/lib/mongo/options/mapper.rb +78 -0
  71. data/lib/mongo/server.rb +2 -2
  72. data/lib/mongo/server/connection_pool/queue.rb +1 -1
  73. data/lib/mongo/server/description.rb +1 -1
  74. data/lib/mongo/server/description/inspector.rb +1 -1
  75. data/lib/mongo/server_selector.rb +1 -1
  76. data/lib/mongo/socket/unix.rb +2 -4
  77. data/lib/mongo/version.rb +1 -1
  78. data/lib/mongo/write_concern/acknowledged.rb +15 -1
  79. data/lib/mongo/write_concern/normalizable.rb +0 -22
  80. data/lib/mongo/write_concern/unacknowledged.rb +12 -0
  81. data/spec/mongo/bulk/bulk_write_spec.rb +178 -91
  82. data/spec/mongo/collection/view/aggregation_spec.rb +14 -1
  83. data/spec/mongo/collection/view/explainable_spec.rb +1 -1
  84. data/spec/mongo/collection/view/map_reduce_spec.rb +2 -2
  85. data/spec/mongo/collection/view/readable_spec.rb +2 -2
  86. data/spec/mongo/collection/view/writable_spec.rb +7 -7
  87. data/spec/mongo/collection/view_spec.rb +14 -5
  88. data/spec/mongo/collection_spec.rb +5 -5
  89. data/spec/mongo/cursor_spec.rb +3 -3
  90. data/spec/mongo/database_spec.rb +4 -8
  91. data/spec/mongo/grid/fs_spec.rb +8 -8
  92. data/spec/mongo/index/view_spec.rb +139 -35
  93. data/spec/mongo/operation/aggregate_spec.rb +14 -22
  94. data/spec/mongo/operation/command_spec.rb +8 -16
  95. data/spec/mongo/operation/map_reduce_spec.rb +1 -1
  96. data/spec/mongo/operation/read/indexes_spec.rb +2 -2
  97. data/spec/mongo/operation/write/bulk_delete_spec.rb +1 -239
  98. data/spec/mongo/operation/write/bulk_insert_spec.rb +3 -234
  99. data/spec/mongo/operation/write/bulk_update_spec.rb +1 -289
  100. data/spec/mongo/operation/write/command/delete_spec.rb +0 -13
  101. data/spec/mongo/operation/write/command/insert_spec.rb +0 -14
  102. data/spec/mongo/operation/write/command/update_spec.rb +0 -14
  103. data/spec/mongo/operation/write/{ensure_index_spec.rb → create_index_spec.rb} +8 -26
  104. data/spec/mongo/operation/write/delete_spec.rb +1 -1
  105. data/spec/mongo/operation/write/drop_index_spec.rb +1 -1
  106. data/spec/mongo/operation/write/insert_spec.rb +3 -3
  107. data/spec/mongo/operation/write/update_spec.rb +1 -1
  108. data/spec/mongo/server_selection_spec.rb +2 -2
  109. data/spec/support/authorization.rb +4 -2
  110. data/spec/support/server_selection.rb +25 -8
  111. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest.yml +4 -10
  112. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_non_matching.yml +6 -12
  113. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Primary.yml +4 -6
  114. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred.yml +4 -10
  115. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred_non_matching.yml +6 -12
  116. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary.yml +4 -10
  117. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred.yml +4 -10
  118. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred_non_matching.yml +6 -12
  119. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_non_matching.yml +6 -12
  120. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest.yml +9 -17
  121. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_non_matching.yml +9 -17
  122. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Primary.yml +6 -10
  123. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred.yml +11 -21
  124. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred_non_matching.yml +11 -18
  125. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary.yml +31 -0
  126. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred.yml +31 -0
  127. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_non_matching.yml +29 -0
  128. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary_non_matching.yml +26 -0
  129. data/spec/support/server_selection/selection/Sharded/read/SecondaryPreferred.yml +4 -10
  130. data/spec/support/server_selection/selection/Single/read/SecondaryPreferred.yml +2 -6
  131. data/spec/support/server_selection/selection/Unknown/read/SecondaryPreferred.yml +0 -2
  132. data/spec/support/shared/bulk_write.rb +109 -72
  133. metadata +29 -10
  134. metadata.gz.sig +0 -0
  135. data/lib/mongo/bulk/bulk_write.rb +0 -307
  136. data/lib/mongo/operation/batchable.rb +0 -103
@@ -67,36 +67,28 @@ describe Mongo::Operation::Aggregate do
67
67
 
68
68
  describe '#execute' do
69
69
 
70
- context 'message' do
70
+ context 'when the aggregation fails' do
71
71
 
72
- it 'creates a query wire protocol message with correct specs' do
73
- allow_any_instance_of(Mongo::ServerSelector::Primary).to receive(:server) do
74
- primary_server
75
- end
72
+ let(:selector) do
73
+ { :aggregate => coll_name,
74
+ :pipeline => [{ '$invalid' => 'operator' }],
75
+ }
76
+ end
76
77
 
77
- expect(Mongo::Protocol::Query).to receive(:new) do |db, coll, sel, options|
78
- expect(db).to eq(db_name)
79
- expect(coll).to eq(Mongo::Database::COMMAND)
80
- expect(sel).to eq(selector)
81
- expect(options).to eq(options)
82
- end
83
- op.execute(primary_context)
78
+ it 'raises an exception' do
79
+ expect {
80
+ op.execute(authorized_primary.context)
81
+ }.to raise_error(Mongo::Error::OperationFailure)
84
82
  end
85
83
  end
86
84
 
87
- context 'connection' do
85
+ context 'rerouting' do
88
86
 
89
- it 'dispatches the message on the connection' do
90
- allow_any_instance_of(Mongo::ServerSelector::Primary).to receive(:server) do
91
- primary_server
87
+ before do
88
+ allow_any_instance_of(Mongo::Operation::Aggregate::Result).to receive(:validate!) do
89
+ true
92
90
  end
93
-
94
- expect(connection).to receive(:dispatch)
95
- op.execute(primary_context)
96
91
  end
97
- end
98
-
99
- context 'rerouting' do
100
92
 
101
93
  context 'when out is specified and server is a secondary' do
102
94
  let(:selector) do
@@ -82,25 +82,17 @@ describe Mongo::Operation::Command do
82
82
  end
83
83
  end
84
84
 
85
- context 'when the command cannot run on a secondary' do
86
-
87
- context 'when the server is a secondary' do
88
-
89
- pending 'it re-routes to the primary'
90
- end
91
- end
92
-
93
85
  context 'when a document exceeds max bson size' do
94
86
 
95
- let(:selector) do
96
- { :ismaster => '1'*17000000 }
97
- end
87
+ let(:selector) do
88
+ { :ismaster => '1'*17000000 }
89
+ end
98
90
 
99
- it 'raises an error' do
100
- expect {
101
- op.execute(authorized_primary.context)
102
- }.to raise_error(Mongo::Error::MaxBSONSize)
103
- end
91
+ it 'raises an error' do
92
+ expect {
93
+ op.execute(authorized_primary.context)
94
+ }.to raise_error(Mongo::Error::MaxBSONSize)
104
95
  end
96
+ end
105
97
  end
106
98
  end
@@ -109,7 +109,7 @@ describe Mongo::Operation::MapReduce do
109
109
  end
110
110
 
111
111
  after do
112
- authorized_collection.find.remove_many
112
+ authorized_collection.find.delete_many
113
113
  end
114
114
 
115
115
  context 'when the map/reduce succeeds' do
@@ -9,11 +9,11 @@ describe Mongo::Operation::Read::Indexes do
9
9
  end
10
10
 
11
11
  before do
12
- authorized_collection.indexes.create(spec, unique: true)
12
+ authorized_collection.indexes.create_one(spec, unique: true)
13
13
  end
14
14
 
15
15
  after do
16
- authorized_collection.indexes.drop(spec)
16
+ authorized_collection.indexes.drop_one('name_1')
17
17
  end
18
18
 
19
19
  let(:operation) do
@@ -73,213 +73,6 @@ describe Mongo::Operation::Write::BulkDelete do
73
73
  end
74
74
  end
75
75
 
76
- describe '#write_concern' do
77
-
78
- let(:other_write_concern) do
79
- { :w => 2 }
80
- end
81
-
82
- context 'when the write concern is set' do
83
-
84
- it 'sets the write concern' do
85
- new_op = op.write_concern(other_write_concern)
86
- expect(new_op.write_concern.options).to eq(other_write_concern)
87
- end
88
- end
89
- end
90
-
91
- describe '#batch' do
92
-
93
- context 'when number of deletes is evenly divisible by n_batches' do
94
- let(:documents) do
95
- [ { q: { a: 1 } },
96
- { q: { b: 1 } },
97
- { q: { c: 1 } },
98
- { q: { d: 1 } },
99
- { q: { e: 1 } },
100
- { q: { f: 1 } } ]
101
- end
102
- let(:n_batches) { 3 }
103
-
104
- it 'batches the op into the divisor number of children ops' do
105
- expect(op.batch(n_batches).size).to eq(n_batches)
106
- end
107
-
108
- it 'divides the deletes evenly between children ops' do
109
- ops = op.batch(n_batches)
110
- batch_size = documents.size / n_batches
111
-
112
- n_batches.times do |i|
113
- start_index = i * batch_size
114
- expect(ops[i].spec[:deletes]).to eq(documents[start_index, batch_size])
115
- end
116
- end
117
- end
118
-
119
- context 'when number of deletes is less than batch size' do
120
- let(:documents) do
121
- [ { q: { a: 1 } } ]
122
- end
123
- let(:n_batches) { 3 }
124
-
125
- it 'raises an exception' do
126
- expect {
127
- op.batch(n_batches)
128
- }.to raise_error(Exception)
129
- end
130
- end
131
-
132
- context 'when number of deletes is not evenly divisible by n_batches' do
133
- let(:documents) do
134
- [ { q: { a: 1 } },
135
- { q: { b: 1 } },
136
- { q: { c: 1 } },
137
- { q: { d: 1 } },
138
- { q: { e: 1 } },
139
- { q: { f: 1 } } ]
140
- end
141
- let(:n_batches) { 4 }
142
-
143
- it 'batches the op into the n_batches number of children ops' do
144
- expect(op.batch(n_batches).size).to eq(n_batches)
145
- end
146
-
147
- it 'divides the deletes evenly between children ops' do
148
- ops = op.batch(n_batches)
149
- batch_size = documents.size / n_batches
150
-
151
- n_batches.times do |i|
152
- start_index = i * batch_size
153
- if i == n_batches - 1
154
- expect(ops[i].spec[:deletes]).to eq(documents[start_index..-1])
155
- else
156
- expect(ops[i].spec[:deletes]).to eq(documents[start_index, batch_size])
157
- end
158
- end
159
- end
160
- end
161
- end
162
-
163
- describe '#merge!' do
164
-
165
- context 'same collection and database' do
166
-
167
- let(:other_docs) do
168
- [ { q: { bar: 1 }, limit: 1 } ]
169
- end
170
-
171
- let(:other_spec) do
172
- { deletes: other_docs,
173
- db_name: db_name,
174
- coll_name: coll_name
175
- }
176
- end
177
-
178
- let(:other) { described_class.new(other_spec) }
179
-
180
- it 'merges the two ops' do
181
- expect{ op.merge!(other) }.not_to raise_exception
182
- end
183
- end
184
-
185
- context 'different database' do
186
-
187
- let(:other_docs) do
188
- [ { q: { bar: 1 }, limit: 1 } ]
189
- end
190
-
191
- let(:other_spec) do
192
- { deletes: other_docs,
193
- db_name: 'different',
194
- coll_name: coll_name
195
- }
196
- end
197
-
198
- let(:other) { described_class.new(other_spec) }
199
-
200
- it 'raises an exception' do
201
- expect do
202
- op.merge!(other)
203
- end.to raise_exception
204
- end
205
- end
206
-
207
- context 'different collection' do
208
-
209
- let(:other_docs) do
210
- [ { q: { bar: 1 }, limit: 1 } ]
211
- end
212
-
213
- let(:other_spec) do
214
- { deletes: other_docs,
215
- db_name: db_name,
216
- coll_name: 'different'
217
- }
218
- end
219
-
220
- let(:other) { described_class.new(other_spec) }
221
-
222
- it 'raises an exception' do
223
- expect do
224
- op.merge!(other)
225
- end.to raise_exception
226
- end
227
- end
228
-
229
- context 'different operation type' do
230
- let(:other) { Mongo::Write::Update.new(spec) }
231
-
232
- it 'raises an exception' do
233
- expect do
234
- op.merge!(other)
235
- end.to raise_exception
236
- end
237
- end
238
-
239
- context 'merged deletes' do
240
-
241
- let(:other_docs) do
242
- [ { q: { bar: 1 }, limit: 1 } ]
243
- end
244
-
245
- let(:other_spec) do
246
- { deletes: other_docs,
247
- db_name: db_name,
248
- coll_name: coll_name
249
- }
250
- end
251
-
252
- let(:other) { described_class.new(other_spec) }
253
-
254
- let(:expected) do
255
- documents + other_docs
256
- end
257
-
258
- it 'merges the list of deletes' do
259
- expect(op.merge!(other).spec[:deletes]).to eq(expected)
260
- end
261
- end
262
-
263
- context 'mutability' do
264
- let(:other_docs) do
265
- [ { q: { bar: 1 }, limit: 1 } ]
266
- end
267
-
268
- let(:other_spec) do
269
- { deletes: other_docs,
270
- db_name: db_name,
271
- coll_name: coll_name
272
- }
273
- end
274
-
275
- let(:other) { described_class.new(other_spec) }
276
-
277
- it 'returns a new object' do
278
- expect(op.merge!(other)).to be(op)
279
- end
280
- end
281
- end
282
-
283
76
  describe '#execute' do
284
77
 
285
78
  before do
@@ -290,7 +83,7 @@ describe Mongo::Operation::Write::BulkDelete do
290
83
  end
291
84
 
292
85
  after do
293
- authorized_collection.find.remove_many
86
+ authorized_collection.find.delete_many
294
87
  end
295
88
 
296
89
  context 'when deleting a single document' do
@@ -438,36 +231,5 @@ describe Mongo::Operation::Write::BulkDelete do
438
231
  end
439
232
  end
440
233
  end
441
-
442
- context 'when a write concern override is specified' do
443
-
444
- let(:documents) do
445
- [ { q: { field: 'test' }, limit: 1 } ]
446
- end
447
-
448
- let(:op) do
449
- described_class.new({
450
- deletes: documents,
451
- db_name: db_name,
452
- coll_name: coll_name,
453
- write_concern: Mongo::WriteConcern.get(w: 1),
454
- ordered: false
455
- })
456
- end
457
-
458
- let(:unacknowledged) do
459
- { w: 0 }
460
- end
461
-
462
- it 'uses that write concern', if: write_command_enabled? do
463
- result = op.write_concern(unacknowledged).execute(authorized_primary.context)
464
- expect(result.replies.size).to eq(1)
465
- end
466
-
467
- it 'uses that write concern', unless: write_command_enabled? do
468
- result = op.write_concern(unacknowledged).execute(authorized_primary.context)
469
- expect(result.replies).to be(nil)
470
- end
471
- end
472
234
  end
473
235
  end
@@ -81,220 +81,15 @@ describe Mongo::Operation::Write::BulkInsert do
81
81
  end
82
82
  end
83
83
 
84
- describe '#write_concern' do
85
-
86
- let(:other_write_concern) do
87
- { w: 2 }
88
- end
89
-
90
- context 'when the write concern is set' do
91
-
92
- it 'sets the write concern' do
93
- new_op = op.write_concern(other_write_concern)
94
- expect(new_op.write_concern.options).to eq(other_write_concern)
95
- end
96
- end
97
- end
98
-
99
- describe '#batch' do
100
-
101
- context 'when number of inserts is evenly divisible by number of batches' do
102
- let(:documents) do
103
- [ { a: 1 },
104
- { b: 1 },
105
- { c: 1 },
106
- { d: 1 },
107
- { e: 1 },
108
- { f: 1 } ]
109
- end
110
- let(:n_batches) { 3 }
111
-
112
- it 'batches the insert into the n_batches number of children inserts' do
113
- expect(op.batch(n_batches).size).to eq(n_batches)
114
- end
115
-
116
- it 'divides the inserts evenly between children inserts' do
117
- inserts = op.batch(n_batches)
118
- batch_size = documents.size / n_batches
119
-
120
- n_batches.times do |i|
121
- start_index = i * batch_size
122
- expect(inserts[i].spec[:documents]).to eq(documents[start_index, batch_size])
123
- end
124
- end
125
- end
126
-
127
- context 'when number of documents is less than number of batches' do
128
- let(:documents) do
129
- [ { a: 1 } ]
130
- end
131
- let(:n_batches) { 3 }
132
-
133
- it 'raises an exception' do
134
- expect {
135
- op.batch(n_batches)
136
- }.to raise_error(Exception)
137
- end
138
- end
139
-
140
- context 'when number of inserts is not evenly divisible by number of batches' do
141
- let(:documents) do
142
- [ { a: 1 },
143
- { b: 1 },
144
- { c: 1 },
145
- { d: 1 },
146
- { e: 1 },
147
- { f: 1 } ]
148
- end
149
- let(:n_batches) { 4 }
150
-
151
- it 'batches the insert into the n_batches number of children inserts' do
152
- expect(op.batch(n_batches).size).to eq(n_batches)
153
- end
154
-
155
- it 'batches the inserts evenly between children inserts' do
156
- inserts = op.batch(n_batches)
157
- batch_size = documents.size / n_batches
158
-
159
- n_batches.times do |i|
160
- start_index = i * batch_size
161
- if i == n_batches - 1
162
- expect(inserts[i].spec[:documents]).to eq(documents[start_index..-1])
163
- else
164
- expect(inserts[i].spec[:documents]).to eq(documents[start_index, batch_size])
165
- end
166
- end
167
- end
168
- end
169
- end
170
-
171
- describe '#merge!' do
172
-
173
- context 'when collection and database are the same' do
174
-
175
- let(:other_docs) do
176
- [ { bar: 1 } ]
177
- end
178
-
179
- let(:other_spec) do
180
- { :documents => other_docs,
181
- :db_name => db_name,
182
- :coll_name => coll_name
183
- }
184
- end
185
-
186
- let(:other) do
187
- described_class.new(other_spec)
188
- end
189
-
190
- it 'merges the two inserts' do
191
- expect do
192
- op.merge!(other)
193
- end.not_to raise_exception
194
- end
195
- end
196
-
197
- context 'when the database differs' do
198
-
199
- let(:other_docs) do
200
- [ { bar: 1 } ]
201
- end
202
-
203
- let(:other_spec) do
204
- { :documents => other_docs,
205
- :db_name => 'different',
206
- :coll_name => coll_name
207
- }
208
- end
209
-
210
- let(:other) do
211
- described_class.new(other_spec)
212
- end
213
-
214
- it 'raises an exception' do
215
- expect do
216
- op.merge!(other)
217
- end.to raise_exception
218
- end
219
- end
220
-
221
- context 'when the collection differs' do
222
-
223
- let(:other_docs) do
224
- [ { bar: 1 } ]
225
- end
226
-
227
- let(:other_spec) do
228
- { :documents => other_docs,
229
- :db_name => db_name,
230
- :coll_name => 'different'
231
- }
232
- end
233
-
234
- let(:other) do
235
- described_class.new(other_spec)
236
- end
237
-
238
- it 'raises an exception' do
239
- expect do
240
- op.merge!(other)
241
- end.to raise_exception
242
- end
243
- end
244
-
245
- context 'when the command type differs' do
246
-
247
- let(:other) do
248
- Mongo::Write::Update.new(spec)
249
- end
250
-
251
- it 'raises an exception' do
252
- expect do
253
- op.merge!(other)
254
- end.to raise_exception
255
- end
256
- end
257
-
258
- context 'when the commands can be merged' do
259
-
260
- let(:other_docs) do
261
- [ { bar: 1 } ]
262
- end
263
-
264
- let(:other_spec) do
265
- { :documents => other_docs,
266
- :db_name => db_name,
267
- :coll_name => coll_name
268
- }
269
- end
270
-
271
- let(:other) do
272
- described_class.new(other_spec)
273
- end
274
-
275
- let(:expected) do
276
- documents + other_docs
277
- end
278
-
279
- it 'merges the list of documents' do
280
- expect(op.merge!(other).spec[:documents]).to eq(expected)
281
- end
282
-
283
- it 'mutates the original spec' do
284
- expect(op.merge!(other)).to be(op)
285
- end
286
- end
287
- end
288
-
289
84
  describe '#execute' do
290
85
 
291
86
  before do
292
- authorized_collection.indexes.create({ name: 1 }, { unique: true })
87
+ authorized_collection.indexes.create_one({ name: 1 }, { unique: true })
293
88
  end
294
89
 
295
90
  after do
296
- authorized_collection.find.remove_many
297
- authorized_collection.indexes.drop({ name: 1 })
91
+ authorized_collection.find.delete_many
92
+ authorized_collection.indexes.drop_one('name_1')
298
93
  end
299
94
 
300
95
  context 'when inserting a single document' do
@@ -436,31 +231,5 @@ describe Mongo::Operation::Write::BulkInsert do
436
231
  end
437
232
  end
438
233
  end
439
-
440
- context 'when a write concern override is specified' do
441
-
442
- let(:op) do
443
- described_class.new({
444
- documents: documents,
445
- db_name: db_name,
446
- coll_name: coll_name,
447
- write_concern: Mongo::WriteConcern.get(w: 0),
448
- ordered: false
449
- })
450
- end
451
-
452
- let(:documents) do
453
- [{ name: 'test' }, { name: 'test' }, { name: 'test1' }]
454
- end
455
-
456
- let(:acknowledged) do
457
- { w: 1 }
458
- end
459
-
460
- it 'uses that write concern' do
461
- result = op.write_concern(acknowledged).execute(authorized_primary.context)
462
- expect(result.n_inserted).to eq(2)
463
- end
464
- end
465
234
  end
466
235
  end