aboutsummaryrefslogtreecommitdiffstats
path: root/test/visitors
diff options
context:
space:
mode:
Diffstat (limited to 'test/visitors')
-rw-r--r--test/visitors/test_depth_first.rb2
-rw-r--r--test/visitors/test_mssql.rb9
-rw-r--r--test/visitors/test_mysql.rb15
-rw-r--r--test/visitors/test_postgres.rb17
-rw-r--r--test/visitors/test_to_sql.rb6
5 files changed, 39 insertions, 10 deletions
diff --git a/test/visitors/test_depth_first.rb b/test/visitors/test_depth_first.rb
index 6d74926743..06e7bba9fb 100644
--- a/test/visitors/test_depth_first.rb
+++ b/test/visitors/test_depth_first.rb
@@ -63,7 +63,7 @@ module Arel
end
def test_lock
- lock = Nodes::Lock.new
+ lock = Nodes::Lock.new true
@visitor.accept lock
assert_equal [lock], @collector.calls
end
diff --git a/test/visitors/test_mssql.rb b/test/visitors/test_mssql.rb
index b658e46828..ccaea395fe 100644
--- a/test/visitors/test_mssql.rb
+++ b/test/visitors/test_mssql.rb
@@ -13,6 +13,15 @@ module Arel
sql = @visitor.accept(stmt)
sql.must_be_like "SELECT TOP 1"
end
+
+ it 'uses TOP in updates with a limit' do
+ stmt = Nodes::UpdateStatement.new
+ stmt.limit = Nodes::Limit.new(1)
+ stmt.key = 'id'
+ sql = @visitor.accept(stmt)
+ sql.must_be_like "UPDATE NULL WHERE 'id' IN (SELECT TOP 1 'id' )"
+ end
+
end
end
end
diff --git a/test/visitors/test_mysql.rb b/test/visitors/test_mysql.rb
index c3b79ca667..3c15c218b2 100644
--- a/test/visitors/test_mysql.rb
+++ b/test/visitors/test_mysql.rb
@@ -29,11 +29,16 @@ module Arel
sql.must_be_like "SELECT FROM DUAL"
end
- it 'uses FOR UPDATE when locking' do
- stmt = Nodes::SelectStatement.new
- stmt.lock = Nodes::Lock.new
- sql = @visitor.accept(stmt)
- sql.must_be_like "SELECT FROM DUAL FOR UPDATE"
+ describe 'locking' do
+ it 'defaults to FOR UPDATE when locking' do
+ node = Nodes::Lock.new(Arel.sql('FOR UPDATE'))
+ @visitor.accept(node).must_be_like "FOR UPDATE"
+ end
+
+ it 'allows a custom string to be used as a lock' do
+ node = Nodes::Lock.new(Arel.sql('LOCK IN SHARE MODE'))
+ @visitor.accept(node).must_be_like "LOCK IN SHARE MODE"
+ end
end
end
end
diff --git a/test/visitors/test_postgres.rb b/test/visitors/test_postgres.rb
index 8d3f19aa6e..74446c23ba 100644
--- a/test/visitors/test_postgres.rb
+++ b/test/visitors/test_postgres.rb
@@ -7,10 +7,19 @@ module Arel
@visitor = PostgreSQL.new Table.engine
end
- it 'should produce a lock value' do
- @visitor.accept(Nodes::Lock.new).must_be_like %{
- FOR UPDATE
- }
+ describe 'locking' do
+ it 'defaults to FOR UPDATE' do
+ @visitor.accept(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 %{
+ FOR SHARE
+ }
+ end
end
it "should escape LIMIT" do
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb
index 82ad17a82c..3af316037a 100644
--- a/test/visitors/test_to_sql.rb
+++ b/test/visitors/test_to_sql.rb
@@ -20,6 +20,12 @@ module Arel
assert_equal 'omg(*)', @visitor.accept(function)
end
+ it 'should chain predications on named functions' do
+ function = Nodes::NamedFunction.new('omg', [Arel.star])
+ sql = @visitor.accept(function.eq(2))
+ sql.must_be_like %{ omg(*) = 2 }
+ end
+
it 'works with lists' do
function = Nodes::NamedFunction.new('omg', [Arel.star, Arel.star])
assert_equal 'omg(*, *)', @visitor.accept(function)