mongoid 6.0.3 → 6.1.0.rc0
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 +3 -2
- data/lib/config/locales/en.yml +15 -0
- data/lib/mongoid.rb +5 -0
- data/lib/mongoid/clients.rb +10 -2
- data/lib/mongoid/clients/factory.rb +2 -0
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/map_reduce.rb +20 -115
- data/lib/mongoid/contextual/memory.rb +1 -0
- data/lib/mongoid/contextual/mongo.rb +16 -13
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
- data/lib/mongoid/criteria/queryable/optional.rb +14 -0
- data/lib/mongoid/errors.rb +1 -0
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +20 -0
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/extensions.rb +1 -0
- data/lib/mongoid/extensions/decimal128.rb +39 -0
- data/lib/mongoid/indexable/validators/options.rb +2 -1
- data/lib/mongoid/persistable/deletable.rb +3 -7
- data/lib/mongoid/query_cache.rb +2 -2
- data/lib/mongoid/relations/metadata.rb +3 -3
- data/lib/mongoid/relations/referenced/many.rb +2 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +4 -0
- data/spec/app/models/band.rb +1 -0
- data/spec/config/mongoid.yml +19 -0
- data/spec/mongoid/clients/factory_spec.rb +8 -0
- data/spec/mongoid/clients_spec.rb +69 -0
- data/spec/mongoid/config_spec.rb +34 -2
- data/spec/mongoid/contextual/atomic_spec.rb +342 -76
- data/spec/mongoid/contextual/map_reduce_spec.rb +102 -135
- data/spec/mongoid/contextual/memory_spec.rb +316 -56
- data/spec/mongoid/contextual/mongo_spec.rb +366 -4
- data/spec/mongoid/criteria/queryable/optional_spec.rb +13 -0
- data/spec/mongoid/criteria_spec.rb +19 -0
- data/spec/mongoid/extensions/boolean_spec.rb +14 -0
- data/spec/mongoid/extensions/decimal128_spec.rb +44 -0
- data/spec/mongoid/indexable_spec.rb +43 -0
- data/spec/mongoid/query_cache_spec.rb +34 -0
- data/spec/mongoid/relations/metadata_spec.rb +0 -1
- data/spec/mongoid/relations/referenced/many_spec.rb +11 -0
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +11 -0
- data/spec/mongoid/scopable_spec.rb +12 -0
- data/spec/spec_helper.rb +9 -0
- metadata +17 -7
- metadata.gz.sig +0 -0
@@ -32,15 +32,15 @@ describe Mongoid::Contextual::MapReduce do
|
|
32
32
|
Band.collection
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
let(:criteria) do
|
36
|
+
Band.all
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
let(:map_reduce) do
|
40
|
+
described_class.new(collection, criteria, map, reduce)
|
41
|
+
end
|
40
42
|
|
41
|
-
|
42
|
-
described_class.new(collection, criteria, map, reduce)
|
43
|
-
end
|
43
|
+
describe "#command" do
|
44
44
|
|
45
45
|
let(:base_command) do
|
46
46
|
{
|
@@ -51,27 +51,25 @@ describe Mongoid::Contextual::MapReduce do
|
|
51
51
|
}
|
52
52
|
end
|
53
53
|
|
54
|
-
it "returns the db command" do
|
55
|
-
expect(map_reduce.command).to eq(base_command)
|
56
|
-
end
|
57
|
-
|
58
54
|
context "with sort" do
|
55
|
+
|
59
56
|
let(:criteria) do
|
60
57
|
Band.order_by(name: -1)
|
61
58
|
end
|
62
59
|
|
63
|
-
it "
|
64
|
-
expect(map_reduce.command).to eq(
|
60
|
+
it "includes a sort option in the map reduce command" do
|
61
|
+
expect(map_reduce.command[:sort]).to eq('name' => -1)
|
65
62
|
end
|
66
63
|
end
|
67
64
|
|
68
65
|
context "with limit" do
|
66
|
+
|
69
67
|
let(:criteria) do
|
70
68
|
Band.limit(10)
|
71
69
|
end
|
72
70
|
|
73
71
|
it "returns the db command with a limit option" do
|
74
|
-
expect(map_reduce.command).to eq(
|
72
|
+
expect(map_reduce.command[:limit]).to eq(10)
|
75
73
|
end
|
76
74
|
end
|
77
75
|
end
|
@@ -82,10 +80,6 @@ describe Mongoid::Contextual::MapReduce do
|
|
82
80
|
Band.all
|
83
81
|
end
|
84
82
|
|
85
|
-
let(:map_reduce) do
|
86
|
-
described_class.new(collection, criteria, map, reduce)
|
87
|
-
end
|
88
|
-
|
89
83
|
let(:counts) do
|
90
84
|
map_reduce.out(inline: 1).counts
|
91
85
|
end
|
@@ -102,14 +96,6 @@ describe Mongoid::Contextual::MapReduce do
|
|
102
96
|
|
103
97
|
describe "#each" do
|
104
98
|
|
105
|
-
let(:criteria) do
|
106
|
-
Band.all
|
107
|
-
end
|
108
|
-
|
109
|
-
let(:map_reduce) do
|
110
|
-
described_class.new(collection, criteria, map, reduce)
|
111
|
-
end
|
112
|
-
|
113
99
|
context "when the map/reduce is inline" do
|
114
100
|
|
115
101
|
let(:results) do
|
@@ -130,20 +116,40 @@ describe Mongoid::Contextual::MapReduce do
|
|
130
116
|
map_reduce.out(replace: "mr-output")
|
131
117
|
end
|
132
118
|
|
133
|
-
|
134
|
-
|
119
|
+
let(:expected_results) do
|
120
|
+
[
|
135
121
|
{ "_id" => "Depeche Mode", "value" => { "likes" => 200 }},
|
136
122
|
{ "_id" => "Tool", "value" => { "likes" => 100 }}
|
137
|
-
]
|
123
|
+
]
|
124
|
+
end
|
125
|
+
|
126
|
+
it "iterates over the results" do
|
127
|
+
expect(results.entries).to eq(expected_results)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'outputs to the collection' do
|
131
|
+
expect(results.entries).to eq(map_reduce.criteria.view.database["mr-output"].find.to_a)
|
138
132
|
end
|
139
133
|
end
|
140
134
|
|
141
135
|
context "when no output is provided" do
|
142
136
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
137
|
+
context "when the results are iterated" do
|
138
|
+
|
139
|
+
it "raises an error" do
|
140
|
+
expect {
|
141
|
+
map_reduce.entries
|
142
|
+
}.to raise_error(Mongoid::Errors::NoMapReduceOutput)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context "when the statstics are requested" do
|
147
|
+
|
148
|
+
it "raises an error" do
|
149
|
+
expect {
|
150
|
+
map_reduce.counts
|
151
|
+
}.to raise_error(Mongoid::Errors::NoMapReduceOutput)
|
152
|
+
end
|
147
153
|
end
|
148
154
|
end
|
149
155
|
|
@@ -161,17 +167,46 @@ describe Mongoid::Contextual::MapReduce do
|
|
161
167
|
expect(results.entries).to be_empty
|
162
168
|
end
|
163
169
|
end
|
164
|
-
end
|
165
170
|
|
166
|
-
|
171
|
+
context "when there is a collation on the criteria" do
|
167
172
|
|
168
|
-
|
169
|
-
|
170
|
-
|
173
|
+
let(:map) do
|
174
|
+
%Q{
|
175
|
+
function() {
|
176
|
+
emit(this.name, 1);
|
177
|
+
}}
|
178
|
+
end
|
171
179
|
|
172
|
-
|
173
|
-
|
180
|
+
let(:reduce) do
|
181
|
+
%Q{
|
182
|
+
function(key, values) {
|
183
|
+
return Array.sum(values);
|
184
|
+
}}
|
185
|
+
end
|
186
|
+
|
187
|
+
let(:criteria) do
|
188
|
+
Band.where(name: 'DEPECHE MODE').collation(locale: 'en_US', strength: 2)
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'when the server supports collations', if: collation_supported? do
|
192
|
+
|
193
|
+
it 'applies the collation' do
|
194
|
+
expect(map_reduce.out(inline: 1).count).to eq(1)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'when the server does not support collations', unless: collation_supported? do
|
199
|
+
|
200
|
+
it 'raises an exception' do
|
201
|
+
expect {
|
202
|
+
map_reduce.out(inline: 1).to_a
|
203
|
+
}.to raise_exception(Mongo::Error::UnsupportedCollation)
|
204
|
+
end
|
205
|
+
end
|
174
206
|
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "#emitted" do
|
175
210
|
|
176
211
|
let(:emitted) do
|
177
212
|
map_reduce.out(inline: 1).emitted
|
@@ -184,16 +219,8 @@ describe Mongoid::Contextual::MapReduce do
|
|
184
219
|
|
185
220
|
describe "#empty?" do
|
186
221
|
|
187
|
-
let(:map_reduce) do
|
188
|
-
described_class.new(collection, criteria, map, reduce)
|
189
|
-
end
|
190
|
-
|
191
222
|
context "when the map/reduce has results" do
|
192
223
|
|
193
|
-
let(:criteria) do
|
194
|
-
Band.all
|
195
|
-
end
|
196
|
-
|
197
224
|
let(:results) do
|
198
225
|
map_reduce.out(inline: 1)
|
199
226
|
end
|
@@ -221,14 +248,6 @@ describe Mongoid::Contextual::MapReduce do
|
|
221
248
|
|
222
249
|
describe "#finalize" do
|
223
250
|
|
224
|
-
let(:criteria) do
|
225
|
-
Band.all
|
226
|
-
end
|
227
|
-
|
228
|
-
let(:map_reduce) do
|
229
|
-
described_class.new(collection, criteria, map, reduce)
|
230
|
-
end
|
231
|
-
|
232
251
|
let(:finalized) do
|
233
252
|
map_reduce.finalize("testing")
|
234
253
|
end
|
@@ -240,14 +259,6 @@ describe Mongoid::Contextual::MapReduce do
|
|
240
259
|
|
241
260
|
describe "#input" do
|
242
261
|
|
243
|
-
let(:criteria) do
|
244
|
-
Band.all
|
245
|
-
end
|
246
|
-
|
247
|
-
let(:map_reduce) do
|
248
|
-
described_class.new(collection, criteria, map, reduce)
|
249
|
-
end
|
250
|
-
|
251
262
|
let(:input) do
|
252
263
|
map_reduce.out(inline: 1).input
|
253
264
|
end
|
@@ -259,14 +270,6 @@ describe Mongoid::Contextual::MapReduce do
|
|
259
270
|
|
260
271
|
describe "#js_mode" do
|
261
272
|
|
262
|
-
let(:criteria) do
|
263
|
-
Band.all
|
264
|
-
end
|
265
|
-
|
266
|
-
let(:map_reduce) do
|
267
|
-
described_class.new(collection, criteria, map, reduce)
|
268
|
-
end
|
269
|
-
|
270
273
|
let(:results) do
|
271
274
|
map_reduce.out(inline: 1).js_mode
|
272
275
|
end
|
@@ -278,14 +281,6 @@ describe Mongoid::Contextual::MapReduce do
|
|
278
281
|
|
279
282
|
describe "#out" do
|
280
283
|
|
281
|
-
let(:criteria) do
|
282
|
-
Band.all
|
283
|
-
end
|
284
|
-
|
285
|
-
let(:map_reduce) do
|
286
|
-
described_class.new(collection, criteria, map, reduce)
|
287
|
-
end
|
288
|
-
|
289
284
|
context "when providing inline" do
|
290
285
|
|
291
286
|
let(:out) do
|
@@ -293,7 +288,7 @@ describe Mongoid::Contextual::MapReduce do
|
|
293
288
|
end
|
294
289
|
|
295
290
|
it "sets the out command" do
|
296
|
-
expect(out.command[:out]).to eq(
|
291
|
+
expect(out.command[:out][:inline]).to eq(1)
|
297
292
|
end
|
298
293
|
end
|
299
294
|
|
@@ -306,7 +301,7 @@ describe Mongoid::Contextual::MapReduce do
|
|
306
301
|
end
|
307
302
|
|
308
303
|
it "sets the out command value to a string" do
|
309
|
-
expect(out.command[:out]).to eq(
|
304
|
+
expect(out.command[:out][:replace]).to eq('test')
|
310
305
|
end
|
311
306
|
end
|
312
307
|
end
|
@@ -314,14 +309,6 @@ describe Mongoid::Contextual::MapReduce do
|
|
314
309
|
|
315
310
|
describe "#output" do
|
316
311
|
|
317
|
-
let(:criteria) do
|
318
|
-
Band.all
|
319
|
-
end
|
320
|
-
|
321
|
-
let(:map_reduce) do
|
322
|
-
described_class.new(collection, criteria, map, reduce)
|
323
|
-
end
|
324
|
-
|
325
312
|
let(:output) do
|
326
313
|
map_reduce.out(inline: 1).output
|
327
314
|
end
|
@@ -332,40 +319,44 @@ describe Mongoid::Contextual::MapReduce do
|
|
332
319
|
end
|
333
320
|
|
334
321
|
describe "#raw" do
|
335
|
-
let(:criteria) { Band.all }
|
336
|
-
let(:client) { collection.database.client }
|
337
|
-
let(:map_reduce) { described_class.new(collection, criteria, map, reduce) }
|
338
322
|
|
339
|
-
|
323
|
+
let(:client) do
|
324
|
+
collection.database.client
|
325
|
+
end
|
340
326
|
|
341
|
-
|
327
|
+
context "when not specifying an out" do
|
342
328
|
|
343
|
-
|
344
|
-
|
329
|
+
it "raises a NoMapReduceOutput error" do
|
330
|
+
expect {
|
331
|
+
map_reduce.raw
|
332
|
+
}.to raise_error(Mongoid::Errors::NoMapReduceOutput)
|
333
|
+
end
|
334
|
+
end
|
345
335
|
|
346
|
-
|
336
|
+
context "when providing replace" do
|
347
337
|
|
348
|
-
|
349
|
-
|
350
|
-
subject
|
338
|
+
let(:replace_map_reduce) do
|
339
|
+
map_reduce.out(replace: 'output-collection')
|
351
340
|
end
|
352
341
|
|
353
|
-
|
354
|
-
|
342
|
+
context 'when a read preference is defined' do
|
343
|
+
|
344
|
+
let(:criteria) do
|
345
|
+
Band.all.read(mode: :secondary)
|
346
|
+
end
|
347
|
+
|
348
|
+
it "uses the read preference", if: testing_replica_set? do
|
349
|
+
|
350
|
+
expect {
|
351
|
+
replace_map_reduce.raw
|
352
|
+
}.to raise_exception(Mongo::Error::OperationFailure)
|
353
|
+
end
|
355
354
|
end
|
356
355
|
end
|
357
356
|
end
|
358
357
|
|
359
358
|
describe "#reduced" do
|
360
359
|
|
361
|
-
let(:criteria) do
|
362
|
-
Band.all
|
363
|
-
end
|
364
|
-
|
365
|
-
let(:map_reduce) do
|
366
|
-
described_class.new(collection, criteria, map, reduce)
|
367
|
-
end
|
368
|
-
|
369
360
|
let(:reduced) do
|
370
361
|
map_reduce.out(inline: 1).reduced
|
371
362
|
end
|
@@ -377,14 +368,6 @@ describe Mongoid::Contextual::MapReduce do
|
|
377
368
|
|
378
369
|
describe "#scope" do
|
379
370
|
|
380
|
-
let(:criteria) do
|
381
|
-
Band.all
|
382
|
-
end
|
383
|
-
|
384
|
-
let(:map_reduce) do
|
385
|
-
described_class.new(collection, criteria, map, reduce)
|
386
|
-
end
|
387
|
-
|
388
371
|
let(:finalize) do
|
389
372
|
%Q{
|
390
373
|
function(key, value) {
|
@@ -404,14 +387,6 @@ describe Mongoid::Contextual::MapReduce do
|
|
404
387
|
|
405
388
|
describe "#time" do
|
406
389
|
|
407
|
-
let(:criteria) do
|
408
|
-
Band.all
|
409
|
-
end
|
410
|
-
|
411
|
-
let(:map_reduce) do
|
412
|
-
described_class.new(collection, criteria, map, reduce)
|
413
|
-
end
|
414
|
-
|
415
390
|
let(:time) do
|
416
391
|
map_reduce.out(inline: 1).time
|
417
392
|
end
|
@@ -423,14 +398,6 @@ describe Mongoid::Contextual::MapReduce do
|
|
423
398
|
|
424
399
|
describe "#execute" do
|
425
400
|
|
426
|
-
let(:criteria) do
|
427
|
-
Band.all
|
428
|
-
end
|
429
|
-
|
430
|
-
let(:map_reduce) do
|
431
|
-
described_class.new(collection, criteria, map, reduce)
|
432
|
-
end
|
433
|
-
|
434
401
|
let(:execution_results) do
|
435
402
|
map_reduce.out(inline: 1).execute
|
436
403
|
end
|
@@ -47,6 +47,21 @@ describe Mongoid::Contextual::Memory do
|
|
47
47
|
expect(context.send(method)).to be true
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
context 'when there is a collation on the criteria' do
|
52
|
+
|
53
|
+
let(:criteria) do
|
54
|
+
Address.where(street: "hobrecht").tap do |crit|
|
55
|
+
crit.documents = [ hobrecht, friedel ]
|
56
|
+
end.collation(locale: 'en_US', strength: 2)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "raises an exception" do
|
60
|
+
expect {
|
61
|
+
context.send(method)
|
62
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
63
|
+
end
|
64
|
+
end
|
50
65
|
end
|
51
66
|
end
|
52
67
|
|
@@ -77,6 +92,21 @@ describe Mongoid::Contextual::Memory do
|
|
77
92
|
end
|
78
93
|
end
|
79
94
|
|
95
|
+
context 'when there is a collation on the criteria' do
|
96
|
+
|
97
|
+
let(:criteria) do
|
98
|
+
Address.where(street: "hobrecht").tap do |crit|
|
99
|
+
crit.documents = [ hobrecht, friedel ]
|
100
|
+
end.collation(locale: 'en_US', strength: 2)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "raises an exception" do
|
104
|
+
expect {
|
105
|
+
context.count
|
106
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
80
110
|
context "when provided a document" do
|
81
111
|
|
82
112
|
context "when the document matches" do
|
@@ -245,6 +275,21 @@ describe Mongoid::Contextual::Memory do
|
|
245
275
|
expect(deleted).to eq(1)
|
246
276
|
end
|
247
277
|
end
|
278
|
+
|
279
|
+
context 'when there is a collation on the criteria' do
|
280
|
+
|
281
|
+
let(:criteria) do
|
282
|
+
Address.any_in(street: [ "hobrecht", "friedel" ]).tap do |crit|
|
283
|
+
crit.documents = [ hobrecht, friedel, pfluger ]
|
284
|
+
end.collation(locale: 'en_US', strength: 2)
|
285
|
+
end
|
286
|
+
|
287
|
+
it "raises an exception" do
|
288
|
+
expect {
|
289
|
+
context.send(method)
|
290
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
291
|
+
end
|
292
|
+
end
|
248
293
|
end
|
249
294
|
end
|
250
295
|
|
@@ -278,36 +323,54 @@ describe Mongoid::Contextual::Memory do
|
|
278
323
|
|
279
324
|
describe "##{method}" do
|
280
325
|
|
281
|
-
|
282
|
-
context.send(method)
|
283
|
-
end
|
326
|
+
context 'when there is no collation on the criteria' do
|
284
327
|
|
285
|
-
|
286
|
-
|
287
|
-
|
328
|
+
let!(:destroyed) do
|
329
|
+
context.send(method)
|
330
|
+
end
|
288
331
|
|
289
|
-
|
290
|
-
|
291
|
-
|
332
|
+
it "deletes the first matching document" do
|
333
|
+
expect(hobrecht).to be_destroyed
|
334
|
+
end
|
292
335
|
|
293
|
-
|
294
|
-
|
295
|
-
|
336
|
+
it "deletes the last matching document" do
|
337
|
+
expect(friedel).to be_destroyed
|
338
|
+
end
|
296
339
|
|
297
|
-
|
298
|
-
|
299
|
-
|
340
|
+
it "does not delete non matching docs" do
|
341
|
+
expect(pfluger).to_not be_destroyed
|
342
|
+
end
|
300
343
|
|
301
|
-
|
302
|
-
|
303
|
-
|
344
|
+
it "removes the docs from the relation" do
|
345
|
+
expect(person.addresses).to eq([ pfluger ])
|
346
|
+
end
|
347
|
+
|
348
|
+
it "removes the docs from the context" do
|
349
|
+
expect(context.entries).to be_empty
|
350
|
+
end
|
304
351
|
|
305
|
-
|
306
|
-
|
352
|
+
it "persists the changes to the database" do
|
353
|
+
expect(person.reload.addresses).to eq([ pfluger ])
|
354
|
+
end
|
355
|
+
|
356
|
+
it "returns the number of destroyed documents" do
|
357
|
+
expect(destroyed).to eq(2)
|
358
|
+
end
|
307
359
|
end
|
308
360
|
|
309
|
-
|
310
|
-
|
361
|
+
context 'when there is a collation on the criteria' do
|
362
|
+
|
363
|
+
let(:criteria) do
|
364
|
+
Address.any_in(street: [ "hobrecht", "friedel" ]).tap do |crit|
|
365
|
+
crit.documents = [ hobrecht, friedel, pfluger ]
|
366
|
+
end.collation(locale: 'en_US', strength: 2)
|
367
|
+
end
|
368
|
+
|
369
|
+
it "raises an exception" do
|
370
|
+
expect {
|
371
|
+
context.send(method)
|
372
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
373
|
+
end
|
311
374
|
end
|
312
375
|
end
|
313
376
|
end
|
@@ -355,6 +418,21 @@ describe Mongoid::Contextual::Memory do
|
|
355
418
|
expect(context.distinct(:street)).to eq([ "hobrecht", "friedel" ])
|
356
419
|
end
|
357
420
|
end
|
421
|
+
|
422
|
+
context 'when there is a collation on the criteria' do
|
423
|
+
|
424
|
+
let(:criteria) do
|
425
|
+
Address.where(street: "hobrecht").tap do |crit|
|
426
|
+
crit.documents = [ hobrecht, hobrecht, friedel ]
|
427
|
+
end.collation(locale: 'en_US', strength: 2)
|
428
|
+
end
|
429
|
+
|
430
|
+
it "raises an exception" do
|
431
|
+
expect {
|
432
|
+
context.distinct(:street)
|
433
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
434
|
+
end
|
435
|
+
end
|
358
436
|
end
|
359
437
|
|
360
438
|
describe "#each" do
|
@@ -441,6 +519,21 @@ describe Mongoid::Contextual::Memory do
|
|
441
519
|
end
|
442
520
|
end
|
443
521
|
end
|
522
|
+
|
523
|
+
context 'when there is a collation on the criteria' do
|
524
|
+
|
525
|
+
let(:criteria) do
|
526
|
+
Address.where(street: "hobrecht").tap do |crit|
|
527
|
+
crit.documents = [ hobrecht, friedel ]
|
528
|
+
end.collation(locale: 'en_US', strength: 2)
|
529
|
+
end
|
530
|
+
|
531
|
+
it "raises an exception" do
|
532
|
+
expect {
|
533
|
+
context.each
|
534
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
535
|
+
end
|
536
|
+
end
|
444
537
|
end
|
445
538
|
|
446
539
|
describe "#exists?" do
|
@@ -486,6 +579,21 @@ describe Mongoid::Contextual::Memory do
|
|
486
579
|
expect(context).to_not be_exists
|
487
580
|
end
|
488
581
|
end
|
582
|
+
|
583
|
+
context 'when there is a collation on the criteria' do
|
584
|
+
|
585
|
+
let(:criteria) do
|
586
|
+
Address.where(street: "pfluger").tap do |crit|
|
587
|
+
crit.documents = [ hobrecht, friedel ]
|
588
|
+
end.collation(locale: 'en_US', strength: 2)
|
589
|
+
end
|
590
|
+
|
591
|
+
it "raises an exception" do
|
592
|
+
expect {
|
593
|
+
context
|
594
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
595
|
+
end
|
596
|
+
end
|
489
597
|
end
|
490
598
|
|
491
599
|
[ :first, :one ].each do |method|
|
@@ -513,6 +621,21 @@ describe Mongoid::Contextual::Memory do
|
|
513
621
|
it "returns the first matching document" do
|
514
622
|
expect(context.send(method)).to eq(hobrecht)
|
515
623
|
end
|
624
|
+
|
625
|
+
context 'when there is a collation on the criteria' do
|
626
|
+
|
627
|
+
let(:criteria) do
|
628
|
+
Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
|
629
|
+
crit.documents = [ hobrecht, friedel ]
|
630
|
+
end.collation(locale: 'en_US', strength: 2)
|
631
|
+
end
|
632
|
+
|
633
|
+
it "raises an exception" do
|
634
|
+
expect {
|
635
|
+
context.send(method)
|
636
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
637
|
+
end
|
638
|
+
end
|
516
639
|
end
|
517
640
|
end
|
518
641
|
|
@@ -600,6 +723,21 @@ describe Mongoid::Contextual::Memory do
|
|
600
723
|
expect(context).to eq([ hobrecht ])
|
601
724
|
end
|
602
725
|
end
|
726
|
+
|
727
|
+
context 'when there is a collation on the criteria' do
|
728
|
+
|
729
|
+
let(:criteria) do
|
730
|
+
Address.all.limit(1).tap do |crit|
|
731
|
+
crit.documents = [ hobrecht, friedel ]
|
732
|
+
end.collation(locale: 'en_US', strength: 2)
|
733
|
+
end
|
734
|
+
|
735
|
+
it "raises an exception" do
|
736
|
+
expect {
|
737
|
+
context
|
738
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
739
|
+
end
|
740
|
+
end
|
603
741
|
end
|
604
742
|
|
605
743
|
describe "#last" do
|
@@ -625,6 +763,21 @@ describe Mongoid::Contextual::Memory do
|
|
625
763
|
it "returns the last matching document" do
|
626
764
|
expect(context.last).to eq(friedel)
|
627
765
|
end
|
766
|
+
|
767
|
+
context 'when there is a collation on the criteria' do
|
768
|
+
|
769
|
+
let(:criteria) do
|
770
|
+
Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
|
771
|
+
crit.documents = [ hobrecht, friedel ]
|
772
|
+
end.collation(locale: 'en_US', strength: 2)
|
773
|
+
end
|
774
|
+
|
775
|
+
it "raises an exception" do
|
776
|
+
expect {
|
777
|
+
context.last
|
778
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
779
|
+
end
|
780
|
+
end
|
628
781
|
end
|
629
782
|
|
630
783
|
[ :length, :size ].each do |method|
|
@@ -672,6 +825,21 @@ describe Mongoid::Contextual::Memory do
|
|
672
825
|
expect(context.send(method)).to eq(0)
|
673
826
|
end
|
674
827
|
end
|
828
|
+
|
829
|
+
context 'when there is a collation on the criteria' do
|
830
|
+
|
831
|
+
let(:criteria) do
|
832
|
+
Address.where(street: "hobrecht").tap do |crit|
|
833
|
+
crit.documents = [ hobrecht, friedel ]
|
834
|
+
end.collation(locale: 'en_US', strength: 2)
|
835
|
+
end
|
836
|
+
|
837
|
+
it "raises an exception" do
|
838
|
+
expect {
|
839
|
+
context.send(method)
|
840
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
841
|
+
end
|
842
|
+
end
|
675
843
|
end
|
676
844
|
end
|
677
845
|
|
@@ -699,34 +867,52 @@ describe Mongoid::Contextual::Memory do
|
|
699
867
|
described_class.new(criteria)
|
700
868
|
end
|
701
869
|
|
702
|
-
|
703
|
-
context.limit(2)
|
704
|
-
end
|
870
|
+
context 'when there is no collation on the criteria' do
|
705
871
|
|
706
|
-
|
707
|
-
|
708
|
-
|
872
|
+
let!(:limit) do
|
873
|
+
context.limit(2)
|
874
|
+
end
|
709
875
|
|
710
|
-
|
876
|
+
it "returns the context" do
|
877
|
+
expect(limit).to eq(context)
|
878
|
+
end
|
879
|
+
|
880
|
+
context "when asking for all documents" do
|
711
881
|
|
712
|
-
|
882
|
+
context "when only a limit exists" do
|
713
883
|
|
714
|
-
|
715
|
-
|
884
|
+
it "only returns the limited documents" do
|
885
|
+
expect(context.entries).to eq([ hobrecht, friedel ])
|
886
|
+
end
|
716
887
|
end
|
717
|
-
end
|
718
888
|
|
719
|
-
|
889
|
+
context "when a skip and limit exist" do
|
720
890
|
|
721
|
-
|
722
|
-
|
723
|
-
|
891
|
+
before do
|
892
|
+
limit.skip(1)
|
893
|
+
end
|
724
894
|
|
725
|
-
|
726
|
-
|
895
|
+
it "applies the skip before the limit" do
|
896
|
+
expect(context.entries).to eq([ friedel, pfluger ])
|
897
|
+
end
|
727
898
|
end
|
728
899
|
end
|
729
900
|
end
|
901
|
+
|
902
|
+
context 'when there is a collation on the criteria' do
|
903
|
+
|
904
|
+
let(:criteria) do
|
905
|
+
Address.all.tap do |crit|
|
906
|
+
crit.documents = [ hobrecht, friedel, pfluger ]
|
907
|
+
end.collation(locale: 'en_US', strength: 2)
|
908
|
+
end
|
909
|
+
|
910
|
+
it "raises an exception" do
|
911
|
+
expect {
|
912
|
+
context.limit(2)
|
913
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
914
|
+
end
|
915
|
+
end
|
730
916
|
end
|
731
917
|
|
732
918
|
describe "#pluck" do
|
@@ -784,6 +970,21 @@ describe Mongoid::Contextual::Memory do
|
|
784
970
|
end
|
785
971
|
end
|
786
972
|
end
|
973
|
+
|
974
|
+
context 'when there is a collation on the criteria' do
|
975
|
+
|
976
|
+
let(:criteria) do
|
977
|
+
Address.all.tap do |crit|
|
978
|
+
crit.documents = [ hobrecht, friedel ]
|
979
|
+
end.collation(locale: 'en_US', strength: 2)
|
980
|
+
end
|
981
|
+
|
982
|
+
it "raises an exception" do
|
983
|
+
expect {
|
984
|
+
context.pluck(:foo, :bar)
|
985
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
986
|
+
end
|
987
|
+
end
|
787
988
|
end
|
788
989
|
|
789
990
|
describe "#skip" do
|
@@ -810,34 +1011,52 @@ describe Mongoid::Contextual::Memory do
|
|
810
1011
|
described_class.new(criteria)
|
811
1012
|
end
|
812
1013
|
|
813
|
-
|
814
|
-
context.skip(1)
|
815
|
-
end
|
1014
|
+
context 'when there is no collation on the criteria' do
|
816
1015
|
|
817
|
-
|
818
|
-
|
819
|
-
|
1016
|
+
let!(:skip) do
|
1017
|
+
context.skip(1)
|
1018
|
+
end
|
1019
|
+
|
1020
|
+
it "returns the context" do
|
1021
|
+
expect(skip).to eq(context)
|
1022
|
+
end
|
820
1023
|
|
821
|
-
|
1024
|
+
context "when asking for all documents" do
|
822
1025
|
|
823
|
-
|
1026
|
+
context "when only a skip exists" do
|
824
1027
|
|
825
|
-
|
826
|
-
|
1028
|
+
it "skips the correct number" do
|
1029
|
+
expect(context.entries).to eq([ friedel, pfluger ])
|
1030
|
+
end
|
827
1031
|
end
|
828
|
-
end
|
829
1032
|
|
830
|
-
|
1033
|
+
context "when a skip and limit exist" do
|
831
1034
|
|
832
|
-
|
833
|
-
|
834
|
-
|
1035
|
+
before do
|
1036
|
+
skip.limit(1)
|
1037
|
+
end
|
835
1038
|
|
836
|
-
|
837
|
-
|
1039
|
+
it "applies the skip before the limit" do
|
1040
|
+
expect(context.entries).to eq([ friedel ])
|
1041
|
+
end
|
838
1042
|
end
|
839
1043
|
end
|
840
1044
|
end
|
1045
|
+
|
1046
|
+
context 'when there is a collation on the criteria' do
|
1047
|
+
|
1048
|
+
let(:criteria) do
|
1049
|
+
Address.all.tap do |crit|
|
1050
|
+
crit.documents = [ hobrecht, friedel, pfluger ]
|
1051
|
+
end.collation(locale: 'en_US', strength: 2)
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
it "raises an exception" do
|
1055
|
+
expect {
|
1056
|
+
context.skip(1)
|
1057
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
1058
|
+
end
|
1059
|
+
end
|
841
1060
|
end
|
842
1061
|
|
843
1062
|
describe "#sort" do
|
@@ -991,6 +1210,21 @@ describe Mongoid::Contextual::Memory do
|
|
991
1210
|
expect(context.entries).to eq([ friedel, hobrecht, pfluger ])
|
992
1211
|
end
|
993
1212
|
end
|
1213
|
+
|
1214
|
+
context 'when there is a collation on the criteria' do
|
1215
|
+
|
1216
|
+
let(:criteria) do
|
1217
|
+
Address.all.tap do |crit|
|
1218
|
+
crit.documents = [ hobrecht, friedel, pfluger ]
|
1219
|
+
end.collation(locale: 'en_US', strength: 2)
|
1220
|
+
end
|
1221
|
+
|
1222
|
+
it "raises an exception" do
|
1223
|
+
expect {
|
1224
|
+
context.sort(state: 1)
|
1225
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
1226
|
+
end
|
1227
|
+
end
|
994
1228
|
end
|
995
1229
|
|
996
1230
|
describe "#update" do
|
@@ -1118,6 +1352,19 @@ describe Mongoid::Contextual::Memory do
|
|
1118
1352
|
end
|
1119
1353
|
end
|
1120
1354
|
end
|
1355
|
+
|
1356
|
+
context 'when there is a collation on the criteria' do
|
1357
|
+
|
1358
|
+
let(:criteria) do
|
1359
|
+
Address.all.collation(locale: 'en_US', strength: 2)
|
1360
|
+
end
|
1361
|
+
|
1362
|
+
it "raises an exception" do
|
1363
|
+
expect {
|
1364
|
+
context.update
|
1365
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
1366
|
+
end
|
1367
|
+
end
|
1121
1368
|
end
|
1122
1369
|
|
1123
1370
|
describe "#update_all" do
|
@@ -1138,6 +1385,19 @@ describe Mongoid::Contextual::Memory do
|
|
1138
1385
|
person.addresses.create(street: "pfluger")
|
1139
1386
|
end
|
1140
1387
|
|
1388
|
+
context 'when there is a collation on the criteria' do
|
1389
|
+
|
1390
|
+
let(:criteria) do
|
1391
|
+
Address.all.collation(locale: 'en_US', strength: 2)
|
1392
|
+
end
|
1393
|
+
|
1394
|
+
it "raises an exception" do
|
1395
|
+
expect {
|
1396
|
+
context.update_all({})
|
1397
|
+
}.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
1398
|
+
end
|
1399
|
+
end
|
1400
|
+
|
1141
1401
|
context "when the documents are empty" do
|
1142
1402
|
|
1143
1403
|
let(:person_two) do
|