aboutsummaryrefslogtreecommitdiffstats
path: root/test/visitors/test_postgres.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/visitors/test_postgres.rb')
-rw-r--r--test/visitors/test_postgres.rb34
1 files changed, 34 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