Skip to content

Commit

Permalink
Make "not" apply to the whole sub-expression when generating sql.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrempel authored and tenderlove committed Dec 6, 2010
1 parent 516ae52 commit c28fe4c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/arel/visitors/to_sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def visit_Arel_Nodes_On o
end

def visit_Arel_Nodes_Not o
"NOT #{visit o.expr}"
"NOT (#{visit o.expr})"
end

def visit_Arel_Table o
Expand Down
8 changes: 7 additions & 1 deletion test/visitors/test_to_sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ module Visitors

it "should visit_Not" do
sql = @visitor.accept Nodes::Not.new(Arel.sql("foo"))
sql.must_be_like "NOT foo"
sql.must_be_like "NOT (foo)"
end

it "should apply Not to the whole expression" do
node = Nodes::And.new @attr.eq(10), @attr.eq(11)
sql = @visitor.accept Nodes::Not.new(node)
sql.must_be_like %{NOT ("users"."id" = 10 AND "users"."id" = 11)}
end

it "should visit_As" do
Expand Down

0 comments on commit c28fe4c

Please sign in to comment.