aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-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