From c28fe4cbbb1121394c6bb14403350723f9ecce4c Mon Sep 17 00:00:00 2001 From: Ryan Rempel Date: Sat, 4 Dec 2010 12:08:19 -0600 Subject: Make "not" apply to the whole sub-expression when generating sql. --- lib/arel/visitors/to_sql.rb | 2 +- test/visitors/test_to_sql.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index abec5317ca..2713621a54 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -192,7 +192,7 @@ module Arel end def visit_Arel_Nodes_Not o - "NOT #{visit o.expr}" + "NOT (#{visit o.expr})" end def visit_Arel_Table o diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index 1c5c8eac0c..5cbaaac501 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -40,7 +40,13 @@ module Arel 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 -- cgit v1.2.3