diff options
Diffstat (limited to 'test/visitors/test_postgres.rb')
-rw-r--r-- | test/visitors/test_postgres.rb | 36 |
1 files changed, 36 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 |