aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Rempel <rgrempel@gmail.com>2010-12-04 12:08:19 -0600
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-06 09:51:18 -0800
commit4bec8c8e9e21c87a6beb22423fefbd23a7f8fb99 (patch)
tree01abcb3a7550a38783c08e19ef514faf8f40167d
parente4ea62bdec406f0bc8692b6cfad83c17ac6773d6 (diff)
downloadrails-4bec8c8e9e21c87a6beb22423fefbd23a7f8fb99.tar.gz
rails-4bec8c8e9e21c87a6beb22423fefbd23a7f8fb99.tar.bz2
rails-4bec8c8e9e21c87a6beb22423fefbd23a7f8fb99.zip
Make "not" apply to the whole sub-expression when generating sql.
-rw-r--r--lib/arel/visitors/to_sql.rb2
-rw-r--r--test/visitors/test_to_sql.rb8
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 082196ef2b..35a0d9746f 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -221,7 +221,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 04d5e2d39f..bae291d87c 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