mongoid 6.1.0 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/mongoid/atomic.rb +3 -3
  4. data/lib/mongoid/attributes/dynamic.rb +3 -2
  5. data/lib/mongoid/attributes/nested.rb +1 -1
  6. data/lib/mongoid/attributes/processing.rb +0 -4
  7. data/lib/mongoid/attributes.rb +1 -2
  8. data/lib/mongoid/changeable.rb +1 -1
  9. data/lib/mongoid/clients/options.rb +1 -1
  10. data/lib/mongoid/composable.rb +3 -1
  11. data/lib/mongoid/contextual/atomic.rb +1 -1
  12. data/lib/mongoid/contextual/geo_near.rb +3 -2
  13. data/lib/mongoid/contextual/memory.rb +3 -3
  14. data/lib/mongoid/contextual/mongo.rb +5 -5
  15. data/lib/mongoid/contextual/none.rb +14 -2
  16. data/lib/mongoid/copyable.rb +1 -5
  17. data/lib/mongoid/criteria/findable.rb +3 -2
  18. data/lib/mongoid/criteria/includable.rb +2 -2
  19. data/lib/mongoid/criteria/queryable/aggregable.rb +1 -1
  20. data/lib/mongoid/criteria/queryable/extensions/array.rb +1 -1
  21. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
  22. data/lib/mongoid/criteria/queryable/extensions/hash.rb +4 -4
  23. data/lib/mongoid/criteria/queryable/extensions/object.rb +4 -4
  24. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +34 -0
  25. data/lib/mongoid/criteria/queryable/options.rb +16 -0
  26. data/lib/mongoid/criteria/queryable/selector.rb +1 -1
  27. data/lib/mongoid/criteria.rb +2 -2
  28. data/lib/mongoid/document.rb +1 -1
  29. data/lib/mongoid/errors/delete_restriction.rb +2 -2
  30. data/lib/mongoid/errors/inverse_not_found.rb +1 -1
  31. data/lib/mongoid/extensions/hash.rb +3 -2
  32. data/lib/mongoid/extensions/object.rb +2 -2
  33. data/lib/mongoid/extensions/time.rb +1 -1
  34. data/lib/mongoid/factory.rb +0 -1
  35. data/lib/mongoid/fields/foreign_key.rb +2 -2
  36. data/lib/mongoid/findable.rb +1 -1
  37. data/lib/mongoid/indexable/specification.rb +1 -1
  38. data/lib/mongoid/indexable.rb +3 -2
  39. data/lib/mongoid/interceptable.rb +9 -11
  40. data/lib/mongoid/loggable.rb +1 -1
  41. data/lib/mongoid/matchable/all.rb +2 -2
  42. data/lib/mongoid/matchable/and.rb +3 -3
  43. data/lib/mongoid/matchable/default.rb +2 -2
  44. data/lib/mongoid/matchable/elem_match.rb +3 -3
  45. data/lib/mongoid/matchable/exists.rb +2 -2
  46. data/lib/mongoid/matchable/gt.rb +2 -2
  47. data/lib/mongoid/matchable/gte.rb +2 -2
  48. data/lib/mongoid/matchable/in.rb +2 -2
  49. data/lib/mongoid/matchable/lt.rb +2 -2
  50. data/lib/mongoid/matchable/lte.rb +2 -2
  51. data/lib/mongoid/matchable/ne.rb +2 -2
  52. data/lib/mongoid/matchable/nin.rb +2 -2
  53. data/lib/mongoid/matchable/or.rb +3 -3
  54. data/lib/mongoid/matchable/regexp.rb +27 -0
  55. data/lib/mongoid/matchable/size.rb +2 -2
  56. data/lib/mongoid/matchable.rb +16 -9
  57. data/lib/mongoid/persistable/creatable.rb +2 -4
  58. data/lib/mongoid/persistable/deletable.rb +1 -1
  59. data/lib/mongoid/persistable/settable.rb +1 -1
  60. data/lib/mongoid/persistable/upsertable.rb +1 -1
  61. data/lib/mongoid/persistable.rb +0 -3
  62. data/lib/mongoid/persistence_context.rb +2 -3
  63. data/lib/mongoid/relations/accessors.rb +1 -2
  64. data/lib/mongoid/relations/bindings/embedded/in.rb +0 -4
  65. data/lib/mongoid/relations/bindings/embedded/many.rb +1 -8
  66. data/lib/mongoid/relations/bindings/embedded/one.rb +0 -10
  67. data/lib/mongoid/relations/bindings/referenced/many.rb +0 -4
  68. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -4
  69. data/lib/mongoid/relations/builders/embedded/one.rb +1 -1
  70. data/lib/mongoid/relations/builders/nested_attributes/many.rb +1 -1
  71. data/lib/mongoid/relations/conversions.rb +1 -1
  72. data/lib/mongoid/relations/counter_cache.rb +10 -10
  73. data/lib/mongoid/relations/eager/base.rb +4 -4
  74. data/lib/mongoid/relations/eager.rb +6 -11
  75. data/lib/mongoid/relations/embedded/batchable.rb +3 -3
  76. data/lib/mongoid/relations/embedded/in.rb +1 -3
  77. data/lib/mongoid/relations/embedded/many.rb +12 -9
  78. data/lib/mongoid/relations/embedded/one.rb +1 -3
  79. data/lib/mongoid/relations/macros.rb +3 -2
  80. data/lib/mongoid/relations/metadata.rb +3 -3
  81. data/lib/mongoid/relations/nested_builder.rb +1 -1
  82. data/lib/mongoid/relations/proxy.rb +3 -2
  83. data/lib/mongoid/relations/referenced/in.rb +1 -4
  84. data/lib/mongoid/relations/referenced/many.rb +5 -7
  85. data/lib/mongoid/relations/referenced/many_to_many.rb +2 -2
  86. data/lib/mongoid/relations/referenced/one.rb +0 -2
  87. data/lib/mongoid/relations/reflections.rb +2 -2
  88. data/lib/mongoid/relations/synchronization.rb +11 -11
  89. data/lib/mongoid/scopable.rb +2 -2
  90. data/lib/mongoid/serializable.rb +4 -3
  91. data/lib/mongoid/tasks/database.rb +2 -1
  92. data/lib/mongoid/threaded.rb +4 -4
  93. data/lib/mongoid/validatable/macros.rb +4 -2
  94. data/lib/mongoid/validatable.rb +1 -1
  95. data/lib/mongoid/version.rb +1 -1
  96. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +12 -2
  97. data/spec/app/models/book.rb +2 -1
  98. data/spec/app/models/page.rb +1 -1
  99. data/spec/mongoid/contextual/none_spec.rb +15 -0
  100. data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +89 -0
  101. data/spec/mongoid/criteria/queryable/selectable_spec.rb +15 -0
  102. data/spec/mongoid/criteria_spec.rb +6 -2
  103. data/spec/mongoid/interceptable_spec.rb +35 -8
  104. data/spec/mongoid/matchable/all_spec.rb +4 -4
  105. data/spec/mongoid/matchable/and_spec.rb +10 -10
  106. data/spec/mongoid/matchable/default_spec.rb +12 -12
  107. data/spec/mongoid/matchable/elem_match_spec.rb +11 -11
  108. data/spec/mongoid/matchable/exists_spec.rb +5 -5
  109. data/spec/mongoid/matchable/gt_spec.rb +8 -8
  110. data/spec/mongoid/matchable/gte_spec.rb +8 -8
  111. data/spec/mongoid/matchable/in_spec.rb +5 -5
  112. data/spec/mongoid/matchable/lt_spec.rb +8 -8
  113. data/spec/mongoid/matchable/lte_spec.rb +8 -8
  114. data/spec/mongoid/matchable/ne_spec.rb +5 -5
  115. data/spec/mongoid/matchable/nin_spec.rb +5 -5
  116. data/spec/mongoid/matchable/or_spec.rb +7 -7
  117. data/spec/mongoid/matchable/regexp_spec.rb +59 -0
  118. data/spec/mongoid/matchable/size_spec.rb +3 -3
  119. data/spec/mongoid/matchable_spec.rb +108 -58
  120. data/spec/mongoid/persistable/deletable_spec.rb +15 -0
  121. data/spec/mongoid/persistable/settable_spec.rb +16 -0
  122. data/spec/mongoid/persistence_context_spec.rb +22 -1
  123. data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +4 -4
  124. data/spec/mongoid/relations/embedded/many_spec.rb +24 -6
  125. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +1 -1
  126. data/spec/mongoid/relations/synchronization_spec.rb +48 -2
  127. data/spec/mongoid/relations/touchable_spec.rb +40 -0
  128. data/spec/mongoid/validatable/uniqueness_spec.rb +2 -0
  129. data/spec/spec_helper.rb +2 -2
  130. data.tar.gz.sig +0 -0
  131. metadata +10 -5
  132. metadata.gz.sig +1 -1
@@ -2,19 +2,20 @@ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Matchable do
4
4
 
5
- describe "#matches?" do
5
+ describe "#_matches?" do
6
6
 
7
7
  context "when document is embeded" do
8
8
 
9
9
  let(:document) do
10
10
  Address.new(street: "Clarkenwell Road")
11
11
  end
12
+ let(:occupants){[{'name' => 'Tim'}]}
12
13
 
13
14
  before do
14
15
  document.locations << Location.new(
15
16
  name: 'No.1',
16
17
  info: { 'door' => 'Red'},
17
- occupants: [{'name' => 'Tim'}]
18
+ occupants: occupants
18
19
  )
19
20
  end
20
21
 
@@ -25,7 +26,7 @@ describe Mongoid::Matchable do
25
26
  end
26
27
 
27
28
  it "returns false" do
28
- expect(document.locations.first.matches?(selector)).to be false
29
+ expect(document.locations.first._matches?(selector)).to be false
29
30
  end
30
31
 
31
32
  context "when just change the selector order" do
@@ -35,7 +36,7 @@ describe Mongoid::Matchable do
35
36
  end
36
37
 
37
38
  it "returns false " do
38
- expect(document.locations.first.matches?(selector)).to be false
39
+ expect(document.locations.first._matches?(selector)).to be false
39
40
  end
40
41
  end
41
42
  end
@@ -49,7 +50,7 @@ describe Mongoid::Matchable do
49
50
  end
50
51
 
51
52
  it "returns true" do
52
- expect(document.locations.first.matches?(selector)).to be true
53
+ expect(document.locations.first._matches?(selector)).to be true
53
54
  end
54
55
  end
55
56
 
@@ -60,7 +61,7 @@ describe Mongoid::Matchable do
60
61
  end
61
62
 
62
63
  it "returns false" do
63
- expect(document.locations.first.matches?(selector)).to be false
64
+ expect(document.locations.first._matches?(selector)).to be false
64
65
  end
65
66
  end
66
67
 
@@ -71,7 +72,34 @@ describe Mongoid::Matchable do
71
72
  end
72
73
 
73
74
  it "returns false" do
74
- expect(document.locations.first.matches?(selector)).to be false
75
+ expect(document.locations.first._matches?(selector)).to be false
76
+ end
77
+ end
78
+ end
79
+
80
+ context "when matching index of an array" do
81
+
82
+ let(:occupants){["Tim","Logan"]}
83
+
84
+ context "when the contents match" do
85
+
86
+ let(:selector) do
87
+ { "occupants.0" => "Tim" }
88
+ end
89
+
90
+ it "returns true" do
91
+ expect(document.locations.first._matches?(selector)).to be true
92
+ end
93
+ end
94
+
95
+ context "when the contents do not match" do
96
+
97
+ let(:selector) do
98
+ { "occupants.0" => "Logan" }
99
+ end
100
+
101
+ it "returns false" do
102
+ expect(document.locations.first._matches?(selector)).to be false
75
103
  end
76
104
  end
77
105
  end
@@ -85,7 +113,7 @@ describe Mongoid::Matchable do
85
113
  end
86
114
 
87
115
  it "returns true" do
88
- expect(document.locations.first.matches?(selector)).to be true
116
+ expect(document.locations.first._matches?(selector)).to be true
89
117
  end
90
118
  end
91
119
 
@@ -96,7 +124,7 @@ describe Mongoid::Matchable do
96
124
  end
97
125
 
98
126
  it "returns false" do
99
- expect(document.locations.first.matches?(selector)).to be false
127
+ expect(document.locations.first._matches?(selector)).to be false
100
128
  end
101
129
  end
102
130
 
@@ -107,7 +135,7 @@ describe Mongoid::Matchable do
107
135
  end
108
136
 
109
137
  it "returns false" do
110
- expect(document.locations.first.matches?(selector)).to be false
138
+ expect(document.locations.first._matches?(selector)).to be false
111
139
  end
112
140
  end
113
141
  end
@@ -125,7 +153,7 @@ describe Mongoid::Matchable do
125
153
  context "and there is a matching sub document" do
126
154
 
127
155
  it "returns true" do
128
- expect(document.locations.first.matches?(selector)).to be true
156
+ expect(document.locations.first._matches?(selector)).to be true
129
157
  end
130
158
 
131
159
  context "using $in" do
@@ -136,7 +164,7 @@ describe Mongoid::Matchable do
136
164
  end
137
165
 
138
166
  it "returns true" do
139
- expect(document.locations.first.matches?(selector)).to be true
167
+ expect(document.locations.first._matches?(selector)).to be true
140
168
  end
141
169
  end
142
170
  end
@@ -150,7 +178,7 @@ describe Mongoid::Matchable do
150
178
  end
151
179
 
152
180
  it "returns false" do
153
- expect(document.locations.first.matches?(selector)).to be false
181
+ expect(document.locations.first._matches?(selector)).to be false
154
182
  end
155
183
 
156
184
  context "using $in" do
@@ -161,7 +189,7 @@ describe Mongoid::Matchable do
161
189
  end
162
190
 
163
191
  it "returns false" do
164
- expect(document.locations.first.matches?(selector)).to be false
192
+ expect(document.locations.first._matches?(selector)).to be false
165
193
  end
166
194
  end
167
195
  end
@@ -188,7 +216,7 @@ describe Mongoid::Matchable do
188
216
  context "and there is a matching sub document" do
189
217
 
190
218
  it "returns true" do
191
- expect(document.locations.first.matches?(selector)).to be true
219
+ expect(document.locations.first._matches?(selector)).to be true
192
220
  end
193
221
 
194
222
  context "using $in and $ne in the $elemMatch to include the element" do
@@ -200,7 +228,7 @@ describe Mongoid::Matchable do
200
228
  end
201
229
 
202
230
  it "returns true" do
203
- expect(document.locations.first.matches?(selector)).to be true
231
+ expect(document.locations.first._matches?(selector)).to be true
204
232
  end
205
233
  end
206
234
  end
@@ -214,7 +242,7 @@ describe Mongoid::Matchable do
214
242
  end
215
243
 
216
244
  it "returns false" do
217
- expect(document.locations.first.matches?(selector)).to be false
245
+ expect(document.locations.first._matches?(selector)).to be false
218
246
  end
219
247
 
220
248
  context "using $ne in the $elemMatch to exclude the element" do
@@ -226,7 +254,7 @@ describe Mongoid::Matchable do
226
254
  end
227
255
 
228
256
  it "returns false" do
229
- expect(document.locations.first.matches?(selector)).to be false
257
+ expect(document.locations.first._matches?(selector)).to be false
230
258
  end
231
259
  end
232
260
  end
@@ -247,7 +275,7 @@ describe Mongoid::Matchable do
247
275
  end
248
276
 
249
277
  it "returns true" do
250
- expect(document.matches?(selector)).to be true
278
+ expect(document._matches?(selector)).to be true
251
279
  end
252
280
  end
253
281
 
@@ -258,7 +286,29 @@ describe Mongoid::Matchable do
258
286
  end
259
287
 
260
288
  it "returns false" do
261
- expect(document.matches?(selector)).to be false
289
+ expect(document._matches?(selector)).to be false
290
+ end
291
+ end
292
+
293
+ context 'when a BSON::Regexp::Raw object is used' do
294
+
295
+ let(:selector) do
296
+ { street: BSON::Regexp::Raw.new("^Clarkenwell") }
297
+ end
298
+
299
+ it "returns true" do
300
+ expect(document._matches?(selector)).to be true
301
+ end
302
+ end
303
+
304
+ context 'when a native Regexp object is used' do
305
+
306
+ let(:selector) do
307
+ { street: /^Clarkenwell/ }
308
+ end
309
+
310
+ it "returns true" do
311
+ expect(document._matches?(selector)).to be true
262
312
  end
263
313
  end
264
314
  end
@@ -283,7 +333,7 @@ describe Mongoid::Matchable do
283
333
  end
284
334
 
285
335
  it "returns true" do
286
- expect(document.matches?(selector)).to be true
336
+ expect(document._matches?(selector)).to be true
287
337
  end
288
338
  end
289
339
 
@@ -294,7 +344,7 @@ describe Mongoid::Matchable do
294
344
  end
295
345
 
296
346
  it "returns false" do
297
- expect(document.matches?(selector)).to be false
347
+ expect(document._matches?(selector)).to be false
298
348
  end
299
349
  end
300
350
  end
@@ -308,7 +358,7 @@ describe Mongoid::Matchable do
308
358
  end
309
359
 
310
360
  it "returns true" do
311
- expect(document.matches?(selector)).to be true
361
+ expect(document._matches?(selector)).to be true
312
362
  end
313
363
  end
314
364
 
@@ -319,7 +369,7 @@ describe Mongoid::Matchable do
319
369
  end
320
370
 
321
371
  it "returns false" do
322
- expect(document.matches?(selector)).to be false
372
+ expect(document._matches?(selector)).to be false
323
373
  end
324
374
  end
325
375
  end
@@ -333,7 +383,7 @@ describe Mongoid::Matchable do
333
383
  end
334
384
 
335
385
  it "returns true" do
336
- expect(document.matches?(selector)).to be true
386
+ expect(document._matches?(selector)).to be true
337
387
  end
338
388
  end
339
389
 
@@ -344,7 +394,7 @@ describe Mongoid::Matchable do
344
394
  end
345
395
 
346
396
  it "returns false" do
347
- expect(document.matches?(selector)).to be false
397
+ expect(document._matches?(selector)).to be false
348
398
  end
349
399
  end
350
400
  end
@@ -358,7 +408,7 @@ describe Mongoid::Matchable do
358
408
  end
359
409
 
360
410
  it "returns true" do
361
- expect(document.matches?(selector)).to be true
411
+ expect(document._matches?(selector)).to be true
362
412
  end
363
413
  end
364
414
 
@@ -369,7 +419,7 @@ describe Mongoid::Matchable do
369
419
  end
370
420
 
371
421
  it "returns false" do
372
- expect(document.matches?(selector)).to be false
422
+ expect(document._matches?(selector)).to be false
373
423
  end
374
424
  end
375
425
  end
@@ -383,7 +433,7 @@ describe Mongoid::Matchable do
383
433
  end
384
434
 
385
435
  it "returns true" do
386
- expect(document.matches?(selector)).to be true
436
+ expect(document._matches?(selector)).to be true
387
437
  end
388
438
  end
389
439
 
@@ -394,7 +444,7 @@ describe Mongoid::Matchable do
394
444
  end
395
445
 
396
446
  it "returns false" do
397
- expect(document.matches?(selector)).to be false
447
+ expect(document._matches?(selector)).to be false
398
448
  end
399
449
  end
400
450
  end
@@ -408,7 +458,7 @@ describe Mongoid::Matchable do
408
458
  end
409
459
 
410
460
  it "returns true" do
411
- expect(document.matches?(selector)).to be true
461
+ expect(document._matches?(selector)).to be true
412
462
  end
413
463
  end
414
464
 
@@ -419,7 +469,7 @@ describe Mongoid::Matchable do
419
469
  end
420
470
 
421
471
  it "returns false" do
422
- expect(document.matches?(selector)).to be false
472
+ expect(document._matches?(selector)).to be false
423
473
  end
424
474
  end
425
475
  end
@@ -437,7 +487,7 @@ describe Mongoid::Matchable do
437
487
  end
438
488
 
439
489
  it "returns true" do
440
- expect(document.matches?(selector)).to be true
490
+ expect(document._matches?(selector)).to be true
441
491
  end
442
492
  end
443
493
 
@@ -450,7 +500,7 @@ describe Mongoid::Matchable do
450
500
  end
451
501
 
452
502
  it "returns false" do
453
- expect(document.matches?(selector)).to be false
503
+ expect(document._matches?(selector)).to be false
454
504
  end
455
505
  end
456
506
  end
@@ -470,7 +520,7 @@ describe Mongoid::Matchable do
470
520
  end
471
521
 
472
522
  it "returns true" do
473
- expect(document.matches?(selector)).to be true
523
+ expect(document._matches?(selector)).to be true
474
524
  end
475
525
  end
476
526
 
@@ -483,7 +533,7 @@ describe Mongoid::Matchable do
483
533
  end
484
534
 
485
535
  it "returns false" do
486
- expect(document.matches?(selector)).to be false
536
+ expect(document._matches?(selector)).to be false
487
537
  end
488
538
  end
489
539
  end
@@ -499,7 +549,7 @@ describe Mongoid::Matchable do
499
549
  end
500
550
 
501
551
  it "returns true" do
502
- expect(document.matches?(selector)).to be true
552
+ expect(document._matches?(selector)).to be true
503
553
  end
504
554
  end
505
555
 
@@ -512,7 +562,7 @@ describe Mongoid::Matchable do
512
562
  end
513
563
 
514
564
  it "returns false" do
515
- expect(document.matches?(selector)).to be false
565
+ expect(document._matches?(selector)).to be false
516
566
  end
517
567
  end
518
568
  end
@@ -530,7 +580,7 @@ describe Mongoid::Matchable do
530
580
  end
531
581
 
532
582
  it "returns true" do
533
- expect(document.matches?(selector)).to be true
583
+ expect(document._matches?(selector)).to be true
534
584
  end
535
585
  end
536
586
 
@@ -543,7 +593,7 @@ describe Mongoid::Matchable do
543
593
  end
544
594
 
545
595
  it "returns false" do
546
- expect(document.matches?(selector)).to be false
596
+ expect(document._matches?(selector)).to be false
547
597
  end
548
598
  end
549
599
  end
@@ -558,7 +608,7 @@ describe Mongoid::Matchable do
558
608
  end
559
609
 
560
610
  it "returns true" do
561
- expect(document.matches?(selector)).to be true
611
+ expect(document._matches?(selector)).to be true
562
612
  end
563
613
  end
564
614
 
@@ -569,7 +619,7 @@ describe Mongoid::Matchable do
569
619
  end
570
620
 
571
621
  it "returns false" do
572
- expect(document.matches?(selector)).to be false
622
+ expect(document._matches?(selector)).to be false
573
623
  end
574
624
  end
575
625
  end
@@ -583,7 +633,7 @@ describe Mongoid::Matchable do
583
633
  end
584
634
 
585
635
  it "returns true" do
586
- expect(document.matches?(selector)).to be true
636
+ expect(document._matches?(selector)).to be true
587
637
  end
588
638
  end
589
639
 
@@ -594,7 +644,7 @@ describe Mongoid::Matchable do
594
644
  end
595
645
 
596
646
  it "returns false" do
597
- expect(document.matches?(selector)).to be false
647
+ expect(document._matches?(selector)).to be false
598
648
  end
599
649
  end
600
650
  end
@@ -608,7 +658,7 @@ describe Mongoid::Matchable do
608
658
  end
609
659
 
610
660
  it "returns true" do
611
- expect(document.matches?(selector)).to be true
661
+ expect(document._matches?(selector)).to be true
612
662
  end
613
663
  end
614
664
 
@@ -619,7 +669,7 @@ describe Mongoid::Matchable do
619
669
  end
620
670
 
621
671
  it "returns false" do
622
- expect(document.matches?(selector)).to be false
672
+ expect(document._matches?(selector)).to be false
623
673
  end
624
674
  end
625
675
  end
@@ -633,7 +683,7 @@ describe Mongoid::Matchable do
633
683
  end
634
684
 
635
685
  it "returns true" do
636
- expect(document.matches?(selector)).to be true
686
+ expect(document._matches?(selector)).to be true
637
687
  end
638
688
  end
639
689
 
@@ -644,7 +694,7 @@ describe Mongoid::Matchable do
644
694
  end
645
695
 
646
696
  it "returns false" do
647
- expect(document.matches?(selector)).to be false
697
+ expect(document._matches?(selector)).to be false
648
698
  end
649
699
  end
650
700
  end
@@ -658,7 +708,7 @@ describe Mongoid::Matchable do
658
708
  end
659
709
 
660
710
  it "returns true" do
661
- expect(document.matches?(selector)).to be true
711
+ expect(document._matches?(selector)).to be true
662
712
  end
663
713
  end
664
714
 
@@ -669,7 +719,7 @@ describe Mongoid::Matchable do
669
719
  end
670
720
 
671
721
  it "returns false" do
672
- expect(document.matches?(selector)).to be false
722
+ expect(document._matches?(selector)).to be false
673
723
  end
674
724
  end
675
725
  end
@@ -683,7 +733,7 @@ describe Mongoid::Matchable do
683
733
  end
684
734
 
685
735
  it "returns true" do
686
- expect(document.matches?(selector)).to be true
736
+ expect(document._matches?(selector)).to be true
687
737
  end
688
738
  end
689
739
 
@@ -694,7 +744,7 @@ describe Mongoid::Matchable do
694
744
  end
695
745
 
696
746
  it "returns false" do
697
- expect(document.matches?(selector)).to be false
747
+ expect(document._matches?(selector)).to be false
698
748
  end
699
749
  end
700
750
  end
@@ -708,7 +758,7 @@ describe Mongoid::Matchable do
708
758
  end
709
759
 
710
760
  it "returns true" do
711
- expect(document.matches?(selector)).to be true
761
+ expect(document._matches?(selector)).to be true
712
762
  end
713
763
  end
714
764
 
@@ -719,7 +769,7 @@ describe Mongoid::Matchable do
719
769
  end
720
770
 
721
771
  it "returns false" do
722
- expect(document.matches?(selector)).to be false
772
+ expect(document._matches?(selector)).to be false
723
773
  end
724
774
  end
725
775
  end
@@ -733,7 +783,7 @@ describe Mongoid::Matchable do
733
783
  end
734
784
 
735
785
  it "returns true" do
736
- expect(document.matches?(selector)).to be true
786
+ expect(document._matches?(selector)).to be true
737
787
  end
738
788
  end
739
789
 
@@ -744,7 +794,7 @@ describe Mongoid::Matchable do
744
794
  end
745
795
 
746
796
  it "returns false" do
747
- expect(document.matches?(selector)).to be false
797
+ expect(document._matches?(selector)).to be false
748
798
  end
749
799
  end
750
800
  end
@@ -758,7 +808,7 @@ describe Mongoid::Matchable do
758
808
  end
759
809
 
760
810
  it "returns true" do
761
- expect(document.matches?(selector)).to be true
811
+ expect(document._matches?(selector)).to be true
762
812
  end
763
813
  end
764
814
 
@@ -769,7 +819,7 @@ describe Mongoid::Matchable do
769
819
  end
770
820
 
771
821
  it "returns false" do
772
- expect(document.matches?(selector)).to be false
822
+ expect(document._matches?(selector)).to be false
773
823
  end
774
824
  end
775
825
  end
@@ -213,6 +213,21 @@ describe Mongoid::Persistable::Deletable do
213
213
  expect(removed).to eq(1)
214
214
  end
215
215
  end
216
+
217
+ context "when the conditions need to be mongoized" do
218
+
219
+ let!(:removed) do
220
+ Person.delete_all(id: person.id)
221
+ end
222
+
223
+ it "removes the matching documents" do
224
+ expect(Person.count).to eq(1)
225
+ end
226
+
227
+ it "returns the number of documents removed" do
228
+ expect(removed).to eq(1)
229
+ end
230
+ end
216
231
  end
217
232
  end
218
233
  end
@@ -230,6 +230,22 @@ describe Mongoid::Persistable::Settable do
230
230
  end
231
231
  end
232
232
 
233
+ context 'when the field is assigned with nil' do
234
+
235
+ before do
236
+ church.location = nil
237
+ church.set('location.neighborhood' => 'Kreuzberg')
238
+ end
239
+
240
+ it 'updates the hash while keeping existing key and values locally' do
241
+ expect(church.location).to eq({'neighborhood' => 'Kreuzberg'})
242
+ end
243
+
244
+ it 'updates the hash in the database' do
245
+ expect(church.reload.location).to eq({'neighborhood' => 'Kreuzberg'})
246
+ end
247
+ end
248
+
233
249
  context 'when the field type is String' do
234
250
 
235
251
  before do
@@ -211,7 +211,28 @@ describe Mongoid::PersistenceContext do
211
211
  end
212
212
 
213
213
  it 'keeps the other options of the persistence context' do
214
- expect(persistence_context.collection(Person.new).client.options[:read]).to eq(options[:read])
214
+ expect(persistence_context.collection(Person.new).options[:read]).to eq(options[:read])
215
+ end
216
+
217
+ context 'when the parent object has a client set' do
218
+
219
+ let(:file) do
220
+ File.join(File.dirname(__FILE__), "..", "config", "mongoid.yml")
221
+ end
222
+
223
+ before do
224
+ Mongoid::Clients.clear
225
+ Mongoid.load!(file, :test)
226
+ Person.store_in(client: 'reports')
227
+ end
228
+
229
+ after do
230
+ Person.reset_storage_options!
231
+ end
232
+
233
+ it 'uses the client of the parent object' do
234
+ expect(persistence_context.collection(Person.new).client.database.name).to eq('reports')
235
+ end
215
236
  end
216
237
  end
217
238
 
@@ -43,11 +43,11 @@ describe Mongoid::Relations::Bindings::Referenced::ManyToMany do
43
43
  end
44
44
 
45
45
  it "syncs the base" do
46
- expect(person).to be_synced("preference_ids")
46
+ expect(person._synced?("preference_ids")).to be(true)
47
47
  end
48
48
 
49
49
  it "syncs the inverse" do
50
- expect(preference_two).to be_synced("person_ids")
50
+ expect(preference_two._synced?("person_ids")).to be(true)
51
51
  end
52
52
  end
53
53
 
@@ -98,11 +98,11 @@ describe Mongoid::Relations::Bindings::Referenced::ManyToMany do
98
98
  end
99
99
 
100
100
  it "syncs the base" do
101
- expect(person).to be_synced("preference_ids")
101
+ expect(person._synced?("preference_ids")).to be(true)
102
102
  end
103
103
 
104
104
  it "syncs the inverse" do
105
- expect(preference).to be_synced("person_ids")
105
+ expect(preference._synced?("person_ids")).to be(true)
106
106
  end
107
107
  end
108
108