From 557a8769ae5b1e82af0efb1cf07cbc7bc24e3452 Mon Sep 17 00:00:00 2001 From: Roel van der Hoorn Date: Wed, 5 Feb 2014 19:18:56 +0100 Subject: Add tests for PostgreSLQ bugfix regarding invalid SQL in subqueries when using matches() or does_not_match(). --- test/visitors/test_postgres.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/visitors/test_postgres.rb') 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 -- cgit v1.2.3