mongoid 6.1.0 → 6.1.1

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. data/lib/mongoid/atomic.rb +3 -3
  3. data/lib/mongoid/attributes.rb +1 -2
  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/changeable.rb +1 -1
  8. data/lib/mongoid/clients/options.rb +1 -1
  9. data/lib/mongoid/composable.rb +3 -1
  10. data/lib/mongoid/contextual/atomic.rb +1 -1
  11. data/lib/mongoid/contextual/geo_near.rb +3 -2
  12. data/lib/mongoid/contextual/memory.rb +3 -3
  13. data/lib/mongoid/contextual/mongo.rb +5 -5
  14. data/lib/mongoid/contextual/none.rb +14 -2
  15. data/lib/mongoid/copyable.rb +1 -5
  16. data/lib/mongoid/criteria.rb +2 -2
  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/document.rb +1 -1
  28. data/lib/mongoid/errors/delete_restriction.rb +2 -2
  29. data/lib/mongoid/errors/inverse_not_found.rb +1 -1
  30. data/lib/mongoid/extensions/hash.rb +3 -2
  31. data/lib/mongoid/extensions/object.rb +2 -2
  32. data/lib/mongoid/extensions/time.rb +1 -1
  33. data/lib/mongoid/factory.rb +0 -1
  34. data/lib/mongoid/fields/foreign_key.rb +2 -2
  35. data/lib/mongoid/findable.rb +1 -1
  36. data/lib/mongoid/indexable.rb +3 -2
  37. data/lib/mongoid/indexable/specification.rb +1 -1
  38. data/lib/mongoid/interceptable.rb +3 -9
  39. data/lib/mongoid/loggable.rb +1 -1
  40. data/lib/mongoid/matchable.rb +16 -9
  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/persistable.rb +0 -3
  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/persistence_context.rb +2 -3
  62. data/lib/mongoid/relations/accessors.rb +1 -2
  63. data/lib/mongoid/relations/bindings/embedded/in.rb +0 -4
  64. data/lib/mongoid/relations/bindings/embedded/many.rb +1 -8
  65. data/lib/mongoid/relations/bindings/embedded/one.rb +0 -10
  66. data/lib/mongoid/relations/bindings/referenced/many.rb +0 -4
  67. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -4
  68. data/lib/mongoid/relations/builders/embedded/one.rb +1 -1
  69. data/lib/mongoid/relations/builders/nested_attributes/many.rb +1 -1
  70. data/lib/mongoid/relations/conversions.rb +1 -1
  71. data/lib/mongoid/relations/counter_cache.rb +10 -10
  72. data/lib/mongoid/relations/eager.rb +6 -11
  73. data/lib/mongoid/relations/eager/base.rb +4 -4
  74. data/lib/mongoid/relations/embedded/batchable.rb +3 -3
  75. data/lib/mongoid/relations/embedded/in.rb +1 -3
  76. data/lib/mongoid/relations/embedded/many.rb +12 -9
  77. data/lib/mongoid/relations/embedded/one.rb +1 -3
  78. data/lib/mongoid/relations/macros.rb +3 -2
  79. data/lib/mongoid/relations/metadata.rb +3 -3
  80. data/lib/mongoid/relations/nested_builder.rb +1 -1
  81. data/lib/mongoid/relations/proxy.rb +3 -2
  82. data/lib/mongoid/relations/referenced/in.rb +1 -4
  83. data/lib/mongoid/relations/referenced/many.rb +5 -7
  84. data/lib/mongoid/relations/referenced/many_to_many.rb +2 -2
  85. data/lib/mongoid/relations/referenced/one.rb +0 -2
  86. data/lib/mongoid/relations/reflections.rb +2 -2
  87. data/lib/mongoid/relations/synchronization.rb +11 -11
  88. data/lib/mongoid/scopable.rb +2 -2
  89. data/lib/mongoid/serializable.rb +4 -3
  90. data/lib/mongoid/tasks/database.rb +2 -1
  91. data/lib/mongoid/threaded.rb +4 -4
  92. data/lib/mongoid/validatable.rb +1 -1
  93. data/lib/mongoid/validatable/macros.rb +4 -2
  94. data/lib/mongoid/version.rb +1 -1
  95. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +12 -2
  96. data/spec/app/models/book.rb +2 -1
  97. data/spec/app/models/page.rb +1 -1
  98. data/spec/mongoid/contextual/none_spec.rb +15 -0
  99. data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +89 -0
  100. data/spec/mongoid/criteria/queryable/selectable_spec.rb +15 -0
  101. data/spec/mongoid/criteria_spec.rb +6 -2
  102. data/spec/mongoid/interceptable_spec.rb +19 -0
  103. data/spec/mongoid/matchable/all_spec.rb +4 -4
  104. data/spec/mongoid/matchable/and_spec.rb +10 -10
  105. data/spec/mongoid/matchable/default_spec.rb +12 -12
  106. data/spec/mongoid/matchable/elem_match_spec.rb +11 -11
  107. data/spec/mongoid/matchable/exists_spec.rb +5 -5
  108. data/spec/mongoid/matchable/gt_spec.rb +8 -8
  109. data/spec/mongoid/matchable/gte_spec.rb +8 -8
  110. data/spec/mongoid/matchable/in_spec.rb +5 -5
  111. data/spec/mongoid/matchable/lt_spec.rb +8 -8
  112. data/spec/mongoid/matchable/lte_spec.rb +8 -8
  113. data/spec/mongoid/matchable/ne_spec.rb +5 -5
  114. data/spec/mongoid/matchable/nin_spec.rb +5 -5
  115. data/spec/mongoid/matchable/or_spec.rb +7 -7
  116. data/spec/mongoid/matchable/regexp_spec.rb +59 -0
  117. data/spec/mongoid/matchable/size_spec.rb +3 -3
  118. data/spec/mongoid/matchable_spec.rb +108 -58
  119. data/spec/mongoid/persistable/deletable_spec.rb +15 -0
  120. data/spec/mongoid/persistable/settable_spec.rb +16 -0
  121. data/spec/mongoid/persistence_context_spec.rb +22 -1
  122. data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +4 -4
  123. data/spec/mongoid/relations/embedded/many_spec.rb +24 -6
  124. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +1 -1
  125. data/spec/mongoid/relations/synchronization_spec.rb +48 -2
  126. data/spec/mongoid/relations/touchable_spec.rb +40 -0
  127. data/spec/mongoid/validatable/uniqueness_spec.rb +2 -0
  128. data/spec/spec_helper.rb +1 -1
  129. metadata +9 -26
  130. checksums.yaml.gz.sig +0 -0
  131. data.tar.gz.sig +0 -1
  132. metadata.gz.sig +0 -1
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Matchable::Lte do
4
4
 
5
- describe "#matches?" do
5
+ describe "#_matches\?" do
6
6
 
7
7
  context "when the value is larger" do
8
8
 
@@ -11,7 +11,7 @@ describe Mongoid::Matchable::Lte do
11
11
  end
12
12
 
13
13
  it "returns false" do
14
- expect(matcher.matches?("$lte" => 3)).to be false
14
+ expect(matcher._matches?("$lte" => 3)).to be false
15
15
  end
16
16
  end
17
17
 
@@ -22,7 +22,7 @@ describe Mongoid::Matchable::Lte do
22
22
  end
23
23
 
24
24
  it "returns true" do
25
- expect(matcher.matches?("$lte" => 10)).to be true
25
+ expect(matcher._matches?("$lte" => 10)).to be true
26
26
  end
27
27
  end
28
28
 
@@ -33,7 +33,7 @@ describe Mongoid::Matchable::Lte do
33
33
  end
34
34
 
35
35
  it "returns true" do
36
- expect(matcher.matches?("$lte" => 5)).to be true
36
+ expect(matcher._matches?("$lte" => 5)).to be true
37
37
  end
38
38
  end
39
39
 
@@ -44,7 +44,7 @@ describe Mongoid::Matchable::Lte do
44
44
  end
45
45
 
46
46
  it "returns false" do
47
- expect(matcher.matches?("$lte" => 5)).to be false
47
+ expect(matcher._matches?("$lte" => 5)).to be false
48
48
  end
49
49
  end
50
50
 
@@ -56,7 +56,7 @@ describe Mongoid::Matchable::Lte do
56
56
  end
57
57
 
58
58
  it "returns true" do
59
- expect(matcher.matches?("$lte" => 5)).to be true
59
+ expect(matcher._matches?("$lte" => 5)).to be true
60
60
  end
61
61
  end
62
62
 
@@ -66,7 +66,7 @@ describe Mongoid::Matchable::Lte do
66
66
  end
67
67
 
68
68
  it "returns false" do
69
- expect(matcher.matches?("$lte" => 5)).to be false
69
+ expect(matcher._matches?("$lte" => 5)).to be false
70
70
  end
71
71
  end
72
72
  end
@@ -78,7 +78,7 @@ describe Mongoid::Matchable::Lte do
78
78
  end
79
79
 
80
80
  it "returns false" do
81
- expect(matcher.matches?("$lte" => '5.1')).to be false
81
+ expect(matcher._matches?("$lte" => '5.1')).to be false
82
82
  end
83
83
  end
84
84
  end
@@ -6,19 +6,19 @@ describe Mongoid::Matchable::Ne do
6
6
  described_class.new("first")
7
7
  end
8
8
 
9
- describe "#matches?" do
9
+ describe "#_matches?" do
10
10
 
11
11
  context "when the values are not equal" do
12
12
 
13
13
  it "returns true" do
14
- expect(matcher.matches?("$ne" => "second")).to be true
14
+ expect(matcher._matches?("$ne" => "second")).to be true
15
15
  end
16
16
  end
17
17
 
18
18
  context "when the values are equal" do
19
19
 
20
20
  it "returns false" do
21
- expect(matcher.matches?("$ne" => "first")).to be false
21
+ expect(matcher._matches?("$ne" => "first")).to be false
22
22
  end
23
23
  end
24
24
 
@@ -31,14 +31,14 @@ describe Mongoid::Matchable::Ne do
31
31
  context "when the value is in the array" do
32
32
 
33
33
  it "returns false" do
34
- expect(array_matcher.matches?("$ne" => "first")).to be false
34
+ expect(array_matcher._matches?("$ne" => "first")).to be false
35
35
  end
36
36
  end
37
37
 
38
38
  context "when the value is not in the array" do
39
39
 
40
40
  it "returns true" do
41
- expect(array_matcher.matches?("$ne" => "second")).to be true
41
+ expect(array_matcher._matches?("$ne" => "second")).to be true
42
42
  end
43
43
  end
44
44
  end
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Matchable::Nin do
4
4
 
5
- describe "#matches?" do
5
+ describe "#_matches?" do
6
6
 
7
7
  context 'when the attribute is not nil' do
8
8
 
@@ -13,14 +13,14 @@ describe Mongoid::Matchable::Nin do
13
13
  context "when the values do not contain the attribute" do
14
14
 
15
15
  it "returns true" do
16
- expect(matcher.matches?("$nin" => ["second", "third"])).to be true
16
+ expect(matcher._matches?("$nin" => ["second", "third"])).to be true
17
17
  end
18
18
  end
19
19
 
20
20
  context "when the values contain the attribute" do
21
21
 
22
22
  it "returns false" do
23
- expect(matcher.matches?("$nin" => ["first"])).to be false
23
+ expect(matcher._matches?("$nin" => ["first"])).to be false
24
24
  end
25
25
  end
26
26
  end
@@ -33,14 +33,14 @@ describe Mongoid::Matchable::Nin do
33
33
  context "when the values do not contain the attribute" do
34
34
 
35
35
  it "returns true" do
36
- expect(matcher.matches?("$nin" => ["third"])).to be true
36
+ expect(matcher._matches?("$nin" => ["third"])).to be true
37
37
  end
38
38
  end
39
39
 
40
40
  context "when the values contain the attribute" do
41
41
 
42
42
  it "returns false" do
43
- expect(matcher.matches?("$nin" => [/\Afir.*\z/, nil])).to be false
43
+ expect(matcher._matches?("$nin" => [/\Afir.*\z/, nil])).to be false
44
44
  end
45
45
  end
46
46
  end
@@ -10,14 +10,14 @@ describe Mongoid::Matchable::Or do
10
10
  described_class.new("value", person)
11
11
  end
12
12
 
13
- describe "#matches?" do
13
+ describe "#_matches?" do
14
14
 
15
15
  context "when provided a simple expression" do
16
16
 
17
17
  context "when any of the values are equal" do
18
18
 
19
19
  let(:matches) do
20
- matcher.matches?(
20
+ matcher._matches?(
21
21
  [ { title: "Sir" }, { title: "King" } ]
22
22
  )
23
23
  end
@@ -34,14 +34,14 @@ describe Mongoid::Matchable::Or do
34
34
  context "when none of the values are equal" do
35
35
 
36
36
  it "returns false" do
37
- expect(matcher.matches?([])).to be false
37
+ expect(matcher._matches?([])).to be false
38
38
  end
39
39
  end
40
40
 
41
41
  context "when the expression is a $not" do
42
42
 
43
43
  let(:matches) do
44
- matcher.matches?([ { title: {:$not => /Foobar/ } }])
44
+ matcher._matches?([ { title: {:$not => /Foobar/ } }])
45
45
  end
46
46
 
47
47
  context "when the value matches" do
@@ -69,7 +69,7 @@ describe Mongoid::Matchable::Or do
69
69
  context "when any of the values are equal" do
70
70
 
71
71
  let(:matches) do
72
- matcher.matches?(
72
+ matcher._matches?(
73
73
  [
74
74
  { title: { "$in" => [ "Sir", "Madam" ] } },
75
75
  { title: "King" }
@@ -89,7 +89,7 @@ describe Mongoid::Matchable::Or do
89
89
  context "when none of the values are equal" do
90
90
 
91
91
  let(:matches) do
92
- matcher.matches?(
92
+ matcher._matches?(
93
93
  [
94
94
  { title: { "$in" => [ "Prince", "Madam" ] } },
95
95
  { title: "King" }
@@ -109,7 +109,7 @@ describe Mongoid::Matchable::Or do
109
109
  context "when expression contain multiple fields" do
110
110
 
111
111
  let(:matches) do
112
- matcher.matches?(
112
+ matcher._matches?(
113
113
  [
114
114
  { title: "Sir", age: 23 },
115
115
  { title: "King", age: 100 }
@@ -0,0 +1,59 @@
1
+ require "spec_helper"
2
+
3
+ describe Mongoid::Matchable::Regexp do
4
+
5
+ let(:matcher) do
6
+ described_class.new(attribute)
7
+ end
8
+
9
+ let(:attribute) do
10
+ 'Emily'
11
+ end
12
+
13
+ describe '#_matches?' do
14
+
15
+ context 'when a BSON::Regexp::Raw object is passed' do
16
+
17
+ let(:regexp) do
18
+ BSON::Regexp::Raw.new('^Em')
19
+ end
20
+
21
+ it 'compiles the regexp object to a native regexp for the matching' do
22
+ expect(matcher._matches?(regexp)).to be(true)
23
+ end
24
+
25
+ context 'when the value does not match the attribute' do
26
+
27
+ let(:attribute) do
28
+ 'ily'
29
+ end
30
+
31
+ it 'compiles the regexp object to a native regexp for the matching' do
32
+ expect(matcher._matches?(regexp)).to be(false)
33
+ end
34
+ end
35
+ end
36
+
37
+ context 'when a native Regexp object is passed' do
38
+
39
+ let(:regexp) do
40
+ /^Em/
41
+ end
42
+
43
+ it 'calls super with the native regexp' do
44
+ expect(matcher._matches?(regexp)).to be(true)
45
+ end
46
+
47
+ context 'when the value does not match the attribute' do
48
+
49
+ let(:attribute) do
50
+ 'ily'
51
+ end
52
+
53
+ it 'compiles the regexp object to a native regexp for the matching' do
54
+ expect(matcher._matches?(regexp)).to be(false)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -6,19 +6,19 @@ describe Mongoid::Matchable::Size do
6
6
  described_class.new(["first", "second"])
7
7
  end
8
8
 
9
- describe "#matches?" do
9
+ describe "#_matches?" do
10
10
 
11
11
  context "when the attribute is the same size" do
12
12
 
13
13
  it "returns true" do
14
- expect(matcher.matches?("$size" => 2)).to be true
14
+ expect(matcher._matches?("$size" => 2)).to be true
15
15
  end
16
16
  end
17
17
 
18
18
  context "when the attribute is not the same size" do
19
19
 
20
20
  it "returns false" do
21
- expect(matcher.matches?("$size" => 5)).to be false
21
+ expect(matcher._matches?("$size" => 5)).to be false
22
22
  end
23
23
  end
24
24
  end
@@ -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