Skip to content

Commit c6f9073

Browse files
add test (#5911)
Remove accidental tab
1 parent 6be82fb commit c6f9073

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/mongoid/criteria/queryable/selectable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ def negating?
553553
# @return [ Selectable ] The new selectable.
554554
def not(*criteria)
555555
if criteria.empty?
556-
dup.tap { |query| query.negating = true }
556+
dup.tap { |query| query.negating = !query.negating }
557557
else
558558
criteria.compact.inject(self.clone) do |c, new_s|
559559
if new_s.is_a?(Selectable)

spec/mongoid/criteria/queryable/selectable_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,35 @@ def localized?
19391939
end
19401940
end
19411941

1942+
describe "#not" do
1943+
context "when negating a criterion" do
1944+
let(:selection) do
1945+
query.not(field: /value/)
1946+
end
1947+
1948+
it "adds the $not selector" do
1949+
expect(selection.selector).to eq({
1950+
"field" => { "$not" => /value/ }
1951+
})
1952+
end
1953+
1954+
it "returns a cloned query" do
1955+
expect(selection).to_not equal(query)
1956+
end
1957+
1958+
context "when toggling negation state" do
1959+
it "negates the negating value" do
1960+
expect(query.negating).to be_nil
1961+
negated_query = query.not
1962+
expect(negated_query.negating).to be true
1963+
double_negated_query = negated_query.not
1964+
expect(double_negated_query.negating).to be false
1965+
end
1966+
end
1967+
end
1968+
end
1969+
1970+
19421971
describe Symbol do
19431972

19441973
describe "#all" do

0 commit comments

Comments
 (0)