diff options
author | Roel van der Hoorn <vanderhoorn@gmail.com> | 2014-02-05 19:18:56 +0100 |
---|---|---|
committer | Roel van der Hoorn <vanderhoorn@gmail.com> | 2014-02-05 19:18:56 +0100 |
commit | 557a8769ae5b1e82af0efb1cf07cbc7bc24e3452 (patch) | |
tree | de49c92ab3edec20c126da16f961fb0012e107d3 /test/visitors | |
parent | f3938cd77a2e2602a919c3ce4189f29f056dc68c (diff) | |
download | rails-557a8769ae5b1e82af0efb1cf07cbc7bc24e3452.tar.gz rails-557a8769ae5b1e82af0efb1cf07cbc7bc24e3452.tar.bz2 rails-557a8769ae5b1e82af0efb1cf07cbc7bc24e3452.zip |
Add tests for PostgreSLQ bugfix regarding invalid SQL in subqueries when using matches() or does_not_match().
Diffstat (limited to 'test/visitors')
-rw-r--r-- | test/visitors/test_postgres.rb | 36 | ||||
-rw-r--r-- | test/visitors/test_to_sql.rb | 34 |
2 files changed, 70 insertions, 0 deletions
diff --git a/test/visitors/test_postgres.rb b/test/visitors/test_postgres.rb index 921bd96c1a..dc68279b8d 100644 --- a/test/visitors/test_postgres.rb +++ b/test/visitors/test_postgres.rb @@ -5,6 +5,8 @@ module Arel describe 'the postgres visitor' do before do @visitor = PostgreSQL.new Table.engine.connection + @table = Table.new(:users) + @attr = @table[:id] end describe 'locking' do @@ -43,6 +45,40 @@ module Arel core.set_quantifier = Arel::Nodes::Distinct.new assert_equal 'SELECT DISTINCT', @visitor.accept(core) end + + describe "Nodes::Matches" do + it "should know how to visit" do + node = @table[:name].matches('foo%') + @visitor.accept(node).must_be_like %{ + "users"."name" ILIKE 'foo%' + } + end + + it 'can handle subqueries' do + subquery = @table.project(:id).where(@table[:name].matches('foo%')) + node = @attr.in subquery + @visitor.accept(node).must_be_like %{ + "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%') + } + end + end + + describe "Nodes::DoesNotMatch" do + it "should know how to visit" do + node = @table[:name].does_not_match('foo%') + @visitor.accept(node).must_be_like %{ + "users"."name" NOT ILIKE 'foo%' + } + end + + it 'can handle subqueries' do + subquery = @table.project(:id).where(@table[:name].does_not_match('foo%')) + node = @attr.in subquery + @visitor.accept(node).must_be_like %{ + "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" NOT ILIKE 'foo%') + } + end + end end end end diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index eb35d1703a..34d3459a27 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -194,6 +194,40 @@ module Arel @visitor.accept(test).must_be_like %{ "users"."bool" = 't' } end + describe "Nodes::Matches" do + it "should know how to visit" do + node = @table[:name].matches('foo%') + @visitor.accept(node).must_be_like %{ + "users"."name" LIKE 'foo%' + } + end + + it 'can handle subqueries' do + subquery = @table.project(:id).where(@table[:name].matches('foo%')) + node = @attr.in subquery + @visitor.accept(node).must_be_like %{ + "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" LIKE 'foo%') + } + end + end + + describe "Nodes::DoesNotMatch" do + it "should know how to visit" do + node = @table[:name].does_not_match('foo%') + @visitor.accept(node).must_be_like %{ + "users"."name" NOT LIKE 'foo%' + } + end + + it 'can handle subqueries' do + subquery = @table.project(:id).where(@table[:name].does_not_match('foo%')) + node = @attr.in subquery + @visitor.accept(node).must_be_like %{ + "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" NOT LIKE 'foo%') + } + end + end + describe "Nodes::Ordering" do it "should know how to visit" do node = @attr.desc |