Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MONGOID-5103 Implement eq symbol operator #5076

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/mongoid/criteria/queryable/selectable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,26 @@ def geo_spacial(criterion)
end
key :within_box, :override, "$geoWithin", "$box"

# Add the $eq criterion to the selector.
#
# @example Add the $eq criterion.
# selectable.eq(age: 60)
#
# @example Execute an $eq in a where query.
# selectable.where(:field.eq => 10)
#
# @param [ Hash ] criterion The field/value pairs to check.
#
# @return [ Selectable ] The cloned selectable.
def eq(criterion)
if criterion.nil?
raise Errors::CriteriaArgumentRequired, :eq
end

__override__(criterion, "$eq")
end
key :eq, :override, "$eq"

# Add the $gt criterion to the selector.
#
# @example Add the $gt criterion.
Expand Down
19 changes: 19 additions & 0 deletions spec/mongoid/criteria_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,25 @@
end
end

describe "#eq" do

let!(:match) do
Band.create(member_count: 5)
end

let!(:non_match) do
Band.create(member_count: 1)
end

let(:criteria) do
Band.eq(member_count: 5)
end

it "returns the matching documents" do
expect(criteria).to eq([ match ])
end
end

describe "#gt" do

let!(:match) do
Expand Down