aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-04-08 17:16:21 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-04-08 17:16:21 -0700
commitb2fb1d3381027176505e8709acd22295fb57597a (patch)
tree5ada9d1e99b2360580fe9b614d633cbdcfc5ecb4 /test
parent93036b168b2877f2fe314b7fa0e8701878e32602 (diff)
downloadrails-b2fb1d3381027176505e8709acd22295fb57597a.tar.gz
rails-b2fb1d3381027176505e8709acd22295fb57597a.tar.bz2
rails-b2fb1d3381027176505e8709acd22295fb57597a.zip
postgresql visitor is working
Diffstat (limited to 'test')
-rw-r--r--test/visitors/test_postgres.rb30
-rw-r--r--test/visitors/test_to_sql.rb3
2 files changed, 18 insertions, 15 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
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb
index 4ed1f225ce..eb102c1905 100644
--- a/test/visitors/test_to_sql.rb
+++ b/test/visitors/test_to_sql.rb
@@ -6,7 +6,6 @@ module Arel
before do
@conn = FakeRecord::Base.new
@visitor = ToSql.new @conn.connection
- @collector = Collectors::SQLString.new
@table = Table.new(:users)
@attr = @table[:id]
end
@@ -33,7 +32,7 @@ module Arel
end
}.new
- viz.accept(@table, @collector)
+ viz.accept(@table, Collectors::SQLString.new)
assert visited, 'hello method was called'
end