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. --- test/visitors/test_to_sql.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'test') 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 From 4018b5d66a810a34273d4b198688896f6f7459f3 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 6 Dec 2010 20:26:08 -0800 Subject: quoting limit nodes --- test/visitors/test_mysql.rb | 6 ++++++ test/visitors/test_postgres.rb | 8 ++++++++ test/visitors/test_to_sql.rb | 6 ++++++ 3 files changed, 20 insertions(+) (limited to 'test') diff --git a/test/visitors/test_mysql.rb b/test/visitors/test_mysql.rb index 8606dc39d4..135348580d 100644 --- a/test/visitors/test_mysql.rb +++ b/test/visitors/test_mysql.rb @@ -17,6 +17,12 @@ module Arel sql.must_be_like "SELECT FROM DUAL LIMIT 18446744073709551615 OFFSET 1" end + it "should escape LIMIT" do + sc = Arel::Nodes::UpdateStatement.new + sc.limit = "omg" + assert_match(/LIMIT 'omg'/, @visitor.accept(sc)) + end + it 'uses DUAL for empty from' do stmt = Nodes::SelectStatement.new sql = @visitor.accept(stmt) diff --git a/test/visitors/test_postgres.rb b/test/visitors/test_postgres.rb index 618745c35d..b98f78ca12 100644 --- a/test/visitors/test_postgres.rb +++ b/test/visitors/test_postgres.rb @@ -12,6 +12,14 @@ module Arel FOR UPDATE } end + + it "should escape LIMIT" do + sc = Arel::Nodes::SelectStatement.new + sc.limit = "omg" + sc.cores.first.projections << 'DISTINCT ON' + sc.orders << "xyz" + assert_match(/LIMIT 'omg'/, @visitor.accept(sc)) + end end end end diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index 5cbaaac501..b9d6c78e62 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -30,6 +30,12 @@ module Arel @visitor.accept(DateTime).must_equal "'DateTime'" end + it "should escape LIMIT" do + sc = Arel::Nodes::SelectStatement.new + sc.limit = "omg" + assert_match(/LIMIT 'omg'/, @visitor.accept(sc)) + end + it "should visit_DateTime" do @visitor.accept DateTime.now end -- cgit v1.2.3