aboutsummaryrefslogtreecommitdiffstats
path: root/test/visitors
diff options
context:
space:
mode:
authorJames Le Cuirot <james.le-cuirot@yakara.com>2014-03-07 13:15:33 +0000
committerJames Le Cuirot <chewi@aura-online.co.uk>2014-04-08 00:39:25 +0100
commit6296617c159d5cee0ba1c76f4ea983e3b5e26b6b (patch)
treefc0ceff2fbf84ef1a1e2214f6fe50844edac882a /test/visitors
parent7515445966b265dd9e90ce4457bff972e1fc3746 (diff)
downloadrails-6296617c159d5cee0ba1c76f4ea983e3b5e26b6b.tar.gz
rails-6296617c159d5cee0ba1c76f4ea983e3b5e26b6b.tar.bz2
rails-6296617c159d5cee0ba1c76f4ea983e3b5e26b6b.zip
Add Regexp and NotRegexp nodes for PostgreSQL
Diffstat (limited to 'test/visitors')
-rw-r--r--test/visitors/test_postgres.rb34
-rw-r--r--test/visitors/test_to_sql.rb20
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