File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
lib/mongoid/criteria/queryable
spec/mongoid/criteria/queryable Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -553,7 +553,7 @@ def negating?
553
553
# @return [ Selectable ] The new selectable.
554
554
def not ( *criteria )
555
555
if criteria . empty?
556
- dup . tap { |query | query . negating = true }
556
+ dup . tap { |query | query . negating = ! query . negating }
557
557
else
558
558
criteria . compact . inject ( self . clone ) do |c , new_s |
559
559
if new_s . is_a? ( Selectable )
Original file line number Diff line number Diff line change @@ -1939,6 +1939,35 @@ def localized?
1939
1939
end
1940
1940
end
1941
1941
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
+
1942
1971
describe Symbol do
1943
1972
1944
1973
describe "#all" do
You can’t perform that action at this time.
0 commit comments