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.rb30
1 files changed, 17 insertions, 13 deletions
diff --git a/test/visitors/test_postgres.rb b/test/visitors/test_postgres.rb
index 995e9bf515..3d646a7324 100644
--- a/test/visitors/test_postgres.rb
+++ b/test/visitors/test_postgres.rb
@@ -9,16 +9,20 @@ module Arel
@attr = @table[:id]
end
+ def compile node
+ @visitor.accept(node, Collectors::SQLString.new).value
+ end
+
describe 'locking' do
it 'defaults to FOR UPDATE' do
- @visitor.accept(Nodes::Lock.new(Arel.sql('FOR UPDATE'))).must_be_like %{
+ compile(Nodes::Lock.new(Arel.sql('FOR UPDATE'))).must_be_like %{
FOR UPDATE
}
end
it 'allows a custom string to be used as a lock' do
node = Nodes::Lock.new(Arel.sql('FOR SHARE'))
- @visitor.accept(node).must_be_like %{
+ compile(node).must_be_like %{
FOR SHARE
}
end
@@ -29,7 +33,7 @@ module Arel
sc.limit = Nodes::Limit.new(Nodes.build_quoted("omg"))
sc.cores.first.projections << Arel.sql('DISTINCT ON')
sc.orders << Arel.sql("xyz")
- sql = @visitor.accept(sc)
+ sql = compile(sc)
assert_match(/LIMIT 'omg'/, sql)
assert_equal 1, sql.scan(/LIMIT/).length, 'should have one limit'
end
@@ -37,19 +41,19 @@ module Arel
it 'should support DISTINCT ON' do
core = Arel::Nodes::SelectCore.new
core.set_quantifier = Arel::Nodes::DistinctOn.new(Arel.sql('aaron'))
- assert_match 'DISTINCT ON ( aaron )', @visitor.accept(core)
+ assert_match 'DISTINCT ON ( aaron )', compile(core)
end
it 'should support DISTINCT' do
core = Arel::Nodes::SelectCore.new
core.set_quantifier = Arel::Nodes::Distinct.new
- assert_equal 'SELECT DISTINCT', @visitor.accept(core)
+ assert_equal 'SELECT DISTINCT', compile(core)
end
describe "Nodes::Matches" do
it "should know how to visit" do
node = @table[:name].matches('foo%')
- @visitor.accept(node).must_be_like %{
+ compile(node).must_be_like %{
"users"."name" ILIKE 'foo%'
}
end
@@ -57,7 +61,7 @@ module Arel
it 'can handle subqueries' do
subquery = @table.project(:id).where(@table[:name].matches('foo%'))
node = @attr.in subquery
- @visitor.accept(node).must_be_like %{
+ compile(node).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%')
}
end
@@ -66,7 +70,7 @@ module Arel
describe "Nodes::DoesNotMatch" do
it "should know how to visit" do
node = @table[:name].does_not_match('foo%')
- @visitor.accept(node).must_be_like %{
+ compile(node).must_be_like %{
"users"."name" NOT ILIKE 'foo%'
}
end
@@ -74,7 +78,7 @@ module Arel
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 %{
+ compile(node).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" NOT ILIKE 'foo%')
}
end
@@ -83,7 +87,7 @@ module Arel
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 %{
+ compile(node).must_be_like %{
"users"."name" ~ 'foo%'
}
end
@@ -91,7 +95,7 @@ module Arel
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 %{
+ compile(node).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" ~ 'foo%')
}
end
@@ -100,7 +104,7 @@ module Arel
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 %{
+ compile(node).must_be_like %{
"users"."name" !~ 'foo%'
}
end
@@ -108,7 +112,7 @@ module Arel
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 %{
+ compile(node).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" !~ 'foo%')
}
end