File tree Expand file tree Collapse file tree 2 files changed +76
-3
lines changed
lib/mongoid/criteria/queryable
spec/mongoid/criteria/queryable Expand file tree Collapse file tree 2 files changed +76
-3
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ def merge!(other)
21
21
other . each_pair do |key , value |
22
22
if value . is_a? ( Hash ) && self [ key . to_s ] . is_a? ( Hash )
23
23
value = self [ key . to_s ] . merge ( value ) do |_key , old_val , new_val |
24
- case _key
24
+ case _key . to_s
25
25
when '$in'
26
26
new_val & old_val
27
27
when '$nin'
Original file line number Diff line number Diff line change 45
45
end
46
46
end
47
47
48
- context "when selector contains a $nin" do
48
+ context "when selector contains a $nin string " do
49
49
50
50
let ( :initial ) do
51
51
{ "$nin" => [ "foo" ] }
73
73
end
74
74
end
75
75
76
- context "when selector contains a $in" do
76
+ context "when selector contains a $nin symbol" do
77
+
78
+ let ( :initial ) do
79
+ { :$nin => [ "foo" ] }
80
+ end
81
+
82
+ before do
83
+ selector [ "field" ] = initial
84
+ end
85
+
86
+ context "when merging in a new $nin" do
87
+
88
+ let ( :other ) do
89
+ { "field" => { :$nin => [ "bar" ] } }
90
+ end
91
+
92
+ before do
93
+ selector . merge! ( other )
94
+ end
95
+
96
+ it "combines the two $nin queries into one" do
97
+ expect ( selector ) . to eq ( {
98
+ "field" => { :$nin => [ "foo" , "bar" ] }
99
+ } )
100
+ end
101
+ end
102
+ end
103
+
104
+ context "when selector contains a $in string" do
77
105
78
106
let ( :initial ) do
79
107
{ "$in" => [ 1 , 2 ] }
118
146
end
119
147
end
120
148
149
+ context "when selector contains a $in symbol" do
150
+
151
+ let ( :initial ) do
152
+ { :$in => [ 1 , 2 ] }
153
+ end
154
+
155
+ before do
156
+ selector [ "field" ] = initial
157
+ end
158
+
159
+ context "when merging in a new $in with an intersecting value" do
160
+
161
+ let ( :other ) do
162
+ { "field" => { :$in => [ 1 ] } }
163
+ end
164
+
165
+ before do
166
+ selector . merge! ( other )
167
+ end
168
+
169
+ it "intersects the $in values" do
170
+ expect ( selector ) . to eq ( {
171
+ "field" => { :$in => [ 1 ] }
172
+ } )
173
+ end
174
+ end
175
+
176
+ context "when merging in a new $in with no intersecting values" do
177
+
178
+ let ( :other ) do
179
+ { "field" => { :$in => [ 3 ] } }
180
+ end
181
+
182
+ before do
183
+ selector . merge! ( other )
184
+ end
185
+
186
+ it "intersects the $in values" do
187
+ expect ( selector ) . to eq ( {
188
+ "field" => { :$in => [ ] }
189
+ } )
190
+ end
191
+ end
192
+ end
193
+
121
194
context "when selector is not nested" do
122
195
123
196
before do
You can’t perform that action at this time.
0 commit comments