Skip to content

Commit

Permalink
add test (#5911)
Browse files Browse the repository at this point in the history
Remove accidental tab
  • Loading branch information
DarshanaVenkatesh authored Dec 6, 2024
1 parent 6be82fb commit c6f9073
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongoid/criteria/queryable/selectable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def negating?
# @return [ Selectable ] The new selectable.
def not(*criteria)
if criteria.empty?
dup.tap { |query| query.negating = true }
dup.tap { |query| query.negating = !query.negating }
else
criteria.compact.inject(self.clone) do |c, new_s|
if new_s.is_a?(Selectable)
Expand Down
29 changes: 29 additions & 0 deletions spec/mongoid/criteria/queryable/selectable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,35 @@ def localized?
end
end

describe "#not" do
context "when negating a criterion" do
let(:selection) do
query.not(field: /value/)
end

it "adds the $not selector" do
expect(selection.selector).to eq({
"field" => { "$not" => /value/ }
})
end

it "returns a cloned query" do
expect(selection).to_not equal(query)
end

context "when toggling negation state" do
it "negates the negating value" do
expect(query.negating).to be_nil
negated_query = query.not
expect(negated_query.negating).to be true
double_negated_query = negated_query.not
expect(double_negated_query.negating).to be false
end
end
end
end


describe Symbol do

describe "#all" do
Expand Down

0 comments on commit c6f9073

Please sign in to comment.