Skip to content

Commit 494bf47

Browse files
committed
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 2cfa2b2 commit 494bf47

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
@@ -3525,6 +3525,21 @@ def self.ages; self; end
35253525
'active' => true, '$and' => [{'active' => false}])
35263526
end
35273527
end
3528+
3529+
# Used to test MONGOID-5251 where the find command was adding unnecessary
3530+
# and clauses. Since the find command creates the criteria and executes it,
3531+
# it is difficult to analyze the criteria used. For this reason, I have
3532+
# extracted the crux of the issue, adding an _id to the the criteria twice,
3533+
# and used that for the test case.
3534+
context "when searching by _id twice" do
3535+
let(:_id) { BSON::ObjectId.new }
3536+
let(:criteria) { Band.where(_id: _id) }
3537+
let(:dup_criteria) { criteria.where(_id: _id)}
3538+
3539+
it "does not duplicate the criteria" do
3540+
expect(dup_criteria.selector).to eq({ "_id" => _id })
3541+
end
3542+
end
35283543
end
35293544

35303545
describe "#for_js" do

0 commit comments

Comments
 (0)