mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add support for a NOT predicate
This commit is contained in:
parent
e13420c86a
commit
0e6888232a
5 changed files with 48 additions and 0 deletions
|
@ -86,6 +86,10 @@ module Arel
|
|||
Predicates::Equality.new(self, other)
|
||||
end
|
||||
|
||||
def not(other)
|
||||
Predicates::Not.new(self, other)
|
||||
end
|
||||
|
||||
def lt(other)
|
||||
Predicates::LessThan.new(self, other)
|
||||
end
|
||||
|
|
|
@ -33,6 +33,7 @@ module Arel
|
|||
end
|
||||
end
|
||||
|
||||
class Not < Binary; end
|
||||
class GreaterThanOrEqualTo < Binary; end
|
||||
class GreaterThan < Binary; end
|
||||
class LessThanOrEqualTo < Binary; end
|
||||
|
|
|
@ -10,6 +10,12 @@ module Arel
|
|||
def operator; :== end
|
||||
end
|
||||
|
||||
class Not < Binary
|
||||
def eval(row)
|
||||
operand1.eval(row) != operand2.eval(row)
|
||||
end
|
||||
end
|
||||
|
||||
class GreaterThanOrEqualTo < Binary
|
||||
def operator; :>= end
|
||||
end
|
||||
|
|
|
@ -26,6 +26,10 @@ module Arel
|
|||
end
|
||||
end
|
||||
|
||||
class Not < Binary
|
||||
def predicate_sql; '!=' end
|
||||
end
|
||||
|
||||
class GreaterThanOrEqualTo < Binary
|
||||
def predicate_sql; '>=' end
|
||||
end
|
||||
|
|
|
@ -49,6 +49,39 @@ share_examples_for 'A Relation' do
|
|||
expected = @expected.select { |r| r[@relation[:age]] == @pivot[@relation[:age]] }
|
||||
@relation.where(@relation[:age].eq(@pivot[@relation[:age]])).should have_rows(expected)
|
||||
end
|
||||
|
||||
it "finds rows with a not predicate" do
|
||||
expected = @expected.select { |r| r[@relation[:age]] != @pivot[@relation[:age]] }
|
||||
@relation.where(@relation[:age].not(@pivot[@relation[:age]])).should have_rows(expected)
|
||||
end
|
||||
|
||||
it "finds rows with a less than predicate" do
|
||||
expected = @expected.select { |r| r[@relation[:age]] < @pivot[@relation[:age]] }
|
||||
@relation.where(@relation[:age].lt(@pivot[@relation[:age]])).should have_rows(expected)
|
||||
end
|
||||
|
||||
it "finds rows with a less than or equal to predicate" do
|
||||
expected = @expected.select { |r| r[@relation[:age]] <= @pivot[@relation[:age]] }
|
||||
@relation.where(@relation[:age].lteq(@pivot[@relation[:age]])).should have_rows(expected)
|
||||
end
|
||||
|
||||
it "finds rows with a greater than predicate" do
|
||||
expected = @expected.select { |r| r[@relation[:age]] > @pivot[@relation[:age]] }
|
||||
@relation.where(@relation[:age].gt(@pivot[@relation[:age]])).should have_rows(expected)
|
||||
end
|
||||
|
||||
it "finds rows with a greater than or equal to predicate" do
|
||||
expected = @expected.select { |r| r[@relation[:age]] >= @pivot[@relation[:age]] }
|
||||
@relation.where(@relation[:age].gteq(@pivot[@relation[:age]])).should have_rows(expected)
|
||||
end
|
||||
|
||||
it "finds rows with a matches predicate"
|
||||
|
||||
it "finds rows with an in predicate" do
|
||||
pending
|
||||
set = @expected[1..(@expected.length/2+1)]
|
||||
@relation.all(:id.in => set.map { |r| r.id }).should have_resources(set)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue