aboutsummaryrefslogtreecommitdiffstats
path: root/test/visitors/test_to_sql.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/visitors/test_to_sql.rb')
-rw-r--r--test/visitors/test_to_sql.rb64
1 files changed, 39 insertions, 25 deletions
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb
index abd8cfe356..7ae5d5b3af 100644
--- a/test/visitors/test_to_sql.rb
+++ b/test/visitors/test_to_sql.rb
@@ -16,9 +16,16 @@ module Arel
end
it 'works with BindParams' do
- node = Nodes::BindParam.new 'omg'
+ node = Nodes::BindParam.new
sql = compile node
- sql.must_be_like 'omg'
+ sql.must_be_like '?'
+ end
+
+ it 'does not quote BindParams used as part of a Values' do
+ bp = Nodes::BindParam.new
+ values = Nodes::Values.new([bp])
+ sql = compile values
+ sql.must_be_like 'VALUES (?)'
end
it 'can define a dispatch method' do
@@ -29,7 +36,7 @@ module Arel
end
def dispatch
- { Arel::Table.name => 'hello' }
+ { Arel::Table => 'hello' }
end
}.new
@@ -174,6 +181,13 @@ module Arel
assert_match(/LIMIT 'omg'/, compile(sc))
end
+ it "should contain a single space before ORDER BY" do
+ table = Table.new(:users)
+ test = table.order(table[:name])
+ sql = compile test
+ assert_match(/"users" ORDER BY/, sql)
+ end
+
it "should quote LIMIT without column type coercion" do
table = Table.new(:users)
sc = table.where(table[:name].eq(0)).take(1).ast
@@ -259,9 +273,9 @@ module Arel
compile(Nodes.build_quoted(nil)).must_be_like "NULL"
end
- it "unsupported input should not raise ArgumentError" do
- error = assert_raises(RuntimeError) { compile(nil) }
- assert_match(/\Aunsupported/, error.message)
+ it "unsupported input should raise UnsupportedVisitError" do
+ error = assert_raises(UnsupportedVisitError) { compile(nil) }
+ assert_match(/\AUnsupported/, error.message)
end
it "should visit_Arel_SelectManager, which is a subquery" do
@@ -284,7 +298,7 @@ module Arel
end
it "should visit_Arel_Nodes_Assignment" do
- column = @table["id"]
+ column = @table["id"]
node = Nodes::Assignment.new(
Nodes::UnqualifiedColumn.new(column),
Nodes::UnqualifiedColumn.new(column)
@@ -375,33 +389,33 @@ module Arel
end
it 'can handle two dot ranges' do
- node = @attr.in 1..3
+ node = @attr.between 1..3
compile(node).must_be_like %{
"users"."id" BETWEEN 1 AND 3
}
end
it 'can handle three dot ranges' do
- node = @attr.in 1...3
+ node = @attr.between 1...3
compile(node).must_be_like %{
"users"."id" >= 1 AND "users"."id" < 3
}
end
it 'can handle ranges bounded by infinity' do
- node = @attr.in 1..Float::INFINITY
+ node = @attr.between 1..Float::INFINITY
compile(node).must_be_like %{
"users"."id" >= 1
}
- node = @attr.in(-Float::INFINITY..3)
+ node = @attr.between(-Float::INFINITY..3)
compile(node).must_be_like %{
"users"."id" <= 3
}
- node = @attr.in(-Float::INFINITY...3)
+ node = @attr.between(-Float::INFINITY...3)
compile(node).must_be_like %{
"users"."id" < 3
}
- node = @attr.in(-Float::INFINITY..Float::INFINITY)
+ node = @attr.between(-Float::INFINITY..Float::INFINITY)
compile(node).must_be_like %{1=1}
end
@@ -479,33 +493,33 @@ module Arel
end
it 'can handle two dot ranges' do
- node = @attr.not_in 1..3
- compile(node).must_be_like %{
- "users"."id" < 1 OR "users"."id" > 3
- }
+ node = @attr.not_between 1..3
+ compile(node).must_equal(
+ %{("users"."id" < 1 OR "users"."id" > 3)}
+ )
end
it 'can handle three dot ranges' do
- node = @attr.not_in 1...3
- compile(node).must_be_like %{
- "users"."id" < 1 OR "users"."id" >= 3
- }
+ node = @attr.not_between 1...3
+ compile(node).must_equal(
+ %{("users"."id" < 1 OR "users"."id" >= 3)}
+ )
end
it 'can handle ranges bounded by infinity' do
- node = @attr.not_in 1..Float::INFINITY
+ node = @attr.not_between 1..Float::INFINITY
compile(node).must_be_like %{
"users"."id" < 1
}
- node = @attr.not_in(-Float::INFINITY..3)
+ node = @attr.not_between(-Float::INFINITY..3)
compile(node).must_be_like %{
"users"."id" > 3
}
- node = @attr.not_in(-Float::INFINITY...3)
+ node = @attr.not_between(-Float::INFINITY...3)
compile(node).must_be_like %{
"users"."id" >= 3
}
- node = @attr.not_in(-Float::INFINITY..Float::INFINITY)
+ node = @attr.not_between(-Float::INFINITY..Float::INFINITY)
compile(node).must_be_like %{1=0}
end