spec/mongoid/criteria/queryable/selector_spec.rb in mongoid-8.0.5 vs spec/mongoid/criteria/queryable/selector_spec.rb in mongoid-8.0.6
- old
+ new
@@ -42,11 +42,11 @@
expect(selector['field']).to eq(10)
end
end
end
- context "when selector contains a $nin" do
+ context "when selector contains a $nin string" do
let(:initial) do
{ "$nin" => ["foo"] }
end
@@ -70,13 +70,41 @@
})
end
end
end
- context "when selector contains a $in" do
+ context "when selector contains a $nin symbol" do
let(:initial) do
+ { :$nin => ["foo"] }
+ end
+
+ before do
+ selector["field"] = initial
+ end
+
+ context "when merging in a new $nin" do
+
+ let(:other) do
+ { "field" => { :$nin => ["bar"] } }
+ end
+
+ before do
+ selector.merge!(other)
+ end
+
+ it "combines the two $nin queries into one" do
+ expect(selector).to eq({
+ "field" => { :$nin => ["foo", "bar"] }
+ })
+ end
+ end
+ end
+
+ context "when selector contains a $in string" do
+
+ let(:initial) do
{ "$in" => [1, 2] }
end
before do
selector["field"] = initial
@@ -110,9 +138,54 @@
end
it "intersects the $in values" do
expect(selector).to eq({
"field" => { "$in" => [] }
+ })
+ end
+ end
+ end
+
+ context "when selector contains a $in symbol" do
+
+ let(:initial) do
+ { :$in => [1, 2] }
+ end
+
+ before do
+ selector["field"] = initial
+ end
+
+ context "when merging in a new $in with an intersecting value" do
+
+ let(:other) do
+ { "field" => { :$in => [1] } }
+ end
+
+ before do
+ selector.merge!(other)
+ end
+
+ it "intersects the $in values" do
+ expect(selector).to eq({
+ "field" => { :$in => [1] }
+ })
+ end
+ end
+
+ context "when merging in a new $in with no intersecting values" do
+
+ let(:other) do
+ { "field" => { :$in => [3] } }
+ end
+
+ before do
+ selector.merge!(other)
+ end
+
+ it "intersects the $in values" do
+ expect(selector).to eq({
+ "field" => { :$in => [] }
})
end
end
end