Skip to content

Commit b2143b3

Browse files
authored
MONGOID-5251 add test case for find generating redundant clauses (#5169)
* MONGOID-5251 add test case for find generating redundant clauses * MONGOID-5251 add comment to test case
1 parent 41a6960 commit b2143b3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

spec/mongoid/criteria_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3644,6 +3644,21 @@ def self.ages; self; end
36443644
'active' => true, '$and' => [{'active' => false}])
36453645
end
36463646
end
3647+
3648+
# Used to test MONGOID-5251 where the find command was adding unnecessary
3649+
# and clauses. Since the find command creates the criteria and executes it,
3650+
# it is difficult to analyze the criteria used. For this reason, I have
3651+
# extracted the crux of the issue, adding an _id to the the criteria twice,
3652+
# and used that for the test case.
3653+
context "when searching by _id twice" do
3654+
let(:_id) { BSON::ObjectId.new }
3655+
let(:criteria) { Band.where(_id: _id) }
3656+
let(:dup_criteria) { criteria.where(_id: _id)}
3657+
3658+
it "does not duplicate the criteria" do
3659+
expect(dup_criteria.selector).to eq({ "_id" => _id })
3660+
end
3661+
end
36473662
end
36483663

36493664
describe "#for_js" do

0 commit comments

Comments
 (0)