diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-07 18:31:37 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-07 18:31:37 -0700 |
commit | 8c6b6542f18914544ef95570ac822bf851ac209b (patch) | |
tree | 69ba0766bceb520a317da4f2fe3a7774ec71d95c /test/visitors | |
parent | d4cc1e33b80a546a58bcd2eaa49ea4c5e9682cbc (diff) | |
parent | 6296617c159d5cee0ba1c76f4ea983e3b5e26b6b (diff) | |
download | rails-8c6b6542f18914544ef95570ac822bf851ac209b.tar.gz rails-8c6b6542f18914544ef95570ac822bf851ac209b.tar.bz2 rails-8c6b6542f18914544ef95570ac822bf851ac209b.zip |
Merge pull request #248 from chewi/master
Add Regexp and NotRegexp nodes for PostgreSQL
Diffstat (limited to 'test/visitors')
-rw-r--r-- | test/visitors/test_postgres.rb | 34 | ||||
-rw-r--r-- | test/visitors/test_to_sql.rb | 20 |
2 files changed, 54 insertions, 0 deletions
diff --git a/test/visitors/test_postgres.rb b/test/visitors/test_postgres.rb index 4287baaf14..995e9bf515 100644 --- a/test/visitors/test_postgres.rb +++ b/test/visitors/test_postgres.rb @@ -79,6 +79,40 @@ module Arel } end end + + describe "Nodes::Regexp" do + it "should know how to visit" do + node = Arel::Nodes::Regexp.new(@table[:name], Nodes.build_quoted('foo%')) + @visitor.accept(node).must_be_like %{ + "users"."name" ~ 'foo%' + } + end + + it 'can handle subqueries' do + subquery = @table.project(:id).where(Arel::Nodes::Regexp.new(@table[:name], Nodes.build_quoted('foo%'))) + node = @attr.in subquery + @visitor.accept(node).must_be_like %{ + "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" ~ 'foo%') + } + end + end + + describe "Nodes::NotRegexp" do + it "should know how to visit" do + node = Arel::Nodes::NotRegexp.new(@table[:name], Nodes.build_quoted('foo%')) + @visitor.accept(node).must_be_like %{ + "users"."name" !~ 'foo%' + } + end + + it 'can handle subqueries' do + subquery = @table.project(:id).where(Arel::Nodes::NotRegexp.new(@table[:name], Nodes.build_quoted('foo%'))) + node = @attr.in subquery + @visitor.accept(node).must_be_like %{ + "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" !~ 'foo%') + } + end + end end end end diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index b142ecd695..644951d71c 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -526,6 +526,26 @@ module Arel end end end + + describe 'Nodes::Regexp' do + it 'raises not implemented error' do + node = Arel::Nodes::Regexp.new(@table[:name], Nodes.build_quoted('foo%')) + + assert_raises(NotImplementedError) do + @visitor.accept(node) + end + end + end + + describe 'Nodes::NotRegexp' do + it 'raises not implemented error' do + node = Arel::Nodes::NotRegexp.new(@table[:name], Nodes.build_quoted('foo%')) + + assert_raises(NotImplementedError) do + @visitor.accept(node) + end + end + end end end end |