1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

AND nodes are supported

This commit is contained in:
Aaron Patterson 2010-08-23 14:44:10 -07:00
parent 3bc3b145ae
commit c151df07ac
6 changed files with 33 additions and 0 deletions

View file

@ -1,6 +1,7 @@
require 'arel/nodes/binary'
require 'arel/nodes/equality'
require 'arel/nodes/or'
require 'arel/nodes/and'
require 'arel/nodes/in'
require 'arel/nodes/count'

6
lib/arel/nodes/and.rb Normal file
View file

@ -0,0 +1,6 @@
module Arel
module Nodes
class And < Arel::Nodes::Binary
end
end
end

View file

@ -12,6 +12,10 @@ module Arel
Nodes::Or.new self, right
end
def and right
Nodes::And.new self, right
end
# FIXME: this method should go away. I don't like people calling
# to_sql on non-head nodes. This forces us to walk the AST until we
# can find a node that has a "relation" member.

View file

@ -86,6 +86,10 @@ module Arel
"#{visit o.left} IN (#{o.right.map { |x| visit x }.join ', '})"
end
def visit_Arel_Nodes_And o
"#{visit o.left} AND #{visit o.right}"
end
def visit_Arel_Nodes_Or o
"#{visit o.left} OR #{visit o.right}"
end

View file

@ -11,6 +11,17 @@ module Arel
check node.right.should == right
end
end
describe 'and' do
it 'makes and AND node' do
attr = Table.new(:users)[:id]
left = attr.eq(10)
right = attr.eq(11)
node = left.and right
check node.left.should == left
check node.right.should == right
end
end
end
end
end

View file

@ -8,6 +8,13 @@ module Arel
@attr = Table.new(:users)[:id]
end
it "should visit_Arel_Nodes_And" do
node = Nodes::And.new @attr.eq(10), @attr.eq(11)
@visitor.accept(node).should be_like %{
"users"."id" = 10 AND "users"."id" = 11
}
end
it "should visit_Arel_Nodes_Or" do
node = Nodes::Or.new @attr.eq(10), @attr.eq(11)
@visitor.accept(node).should be_like %{