diff options
Diffstat (limited to 'test/visitors/test_oracle.rb')
-rw-r--r-- | test/visitors/test_oracle.rb | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/test/visitors/test_oracle.rb b/test/visitors/test_oracle.rb index bd22822bca..bb0fe404e8 100644 --- a/test/visitors/test_oracle.rb +++ b/test/visitors/test_oracle.rb @@ -7,13 +7,17 @@ module Arel @visitor = Oracle.new Table.engine.connection_pool end + def compile node + @visitor.accept(node, Collectors::SQLString.new).value + end + it 'modifies order when there is distinct and first value' do # *sigh* select = "DISTINCT foo.id, FIRST_VALUE(projects.name) OVER (foo) AS alias_0__" stmt = Nodes::SelectStatement.new stmt.cores.first.projections << Nodes::SqlLiteral.new(select) stmt.orders << Nodes::SqlLiteral.new('foo') - sql = @visitor.accept(stmt) + sql = compile(stmt) sql.must_be_like %{ SELECT #{select} ORDER BY alias_0__ } @@ -26,8 +30,8 @@ module Arel stmt.cores.first.projections << Nodes::SqlLiteral.new(select) stmt.orders << Nodes::SqlLiteral.new('foo') - sql = @visitor.accept(stmt) - sql2 = @visitor.accept(stmt) + sql = compile(stmt) + sql2 = compile(stmt) sql.must_equal sql2 end @@ -37,7 +41,7 @@ module Arel stmt = Nodes::SelectStatement.new stmt.cores.first.projections << Nodes::SqlLiteral.new(select) stmt.orders << Nodes::SqlLiteral.new('foo, bar') - sql = @visitor.accept(stmt) + sql = compile(stmt) sql.must_be_like %{ SELECT #{select} ORDER BY alias_0__, alias_1__ } @@ -49,7 +53,7 @@ module Arel stmt = Nodes::SelectStatement.new stmt.cores.first.projections << Nodes::SqlLiteral.new(select) stmt.orders << Nodes::SqlLiteral.new('NVL(LOWER(bar, foo), foo) DESC, UPPER(baz)') - sql = @visitor.accept(stmt) + sql = compile(stmt) sql.must_be_like %{ SELECT #{select} ORDER BY alias_0__ DESC, alias_1__ } @@ -60,7 +64,7 @@ module Arel it 'adds a rownum clause' do stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(10) - sql = @visitor.accept stmt + sql = compile stmt sql.must_be_like %{ SELECT WHERE ROWNUM <= 10 } end @@ -68,8 +72,8 @@ module Arel stmt = Nodes::SelectStatement.new stmt.orders << Nodes::SqlLiteral.new('foo') stmt.limit = Nodes::Limit.new(10) - sql = @visitor.accept stmt - sql2 = @visitor.accept stmt + sql = compile stmt + sql2 = compile stmt sql.must_equal sql2 end @@ -77,9 +81,9 @@ module Arel stmt = Nodes::SelectStatement.new stmt.orders << Nodes::SqlLiteral.new('foo') stmt.limit = Nodes::Limit.new(10) - sql = @visitor.accept stmt + sql = compile stmt sql.must_be_like %{ - SELECT * FROM (SELECT ORDER BY foo) WHERE ROWNUM <= 10 + SELECT * FROM (SELECT ORDER BY foo ) WHERE ROWNUM <= 10 } end @@ -88,9 +92,9 @@ module Arel stmt.cores.first.set_quantifier = Arel::Nodes::Distinct.new stmt.cores.first.projections << Nodes::SqlLiteral.new('id') stmt.limit = Arel::Nodes::Limit.new(10) - sql = @visitor.accept stmt + sql = compile stmt sql.must_be_like %{ - SELECT * FROM (SELECT DISTINCT id) WHERE ROWNUM <= 10 + SELECT * FROM (SELECT DISTINCT id ) WHERE ROWNUM <= 10 } end @@ -98,11 +102,11 @@ module Arel stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(10) stmt.offset = Nodes::Offset.new(10) - sql = @visitor.accept stmt + sql = compile stmt sql.must_be_like %{ SELECT * FROM ( SELECT raw_sql_.*, rownum raw_rnum_ - FROM (SELECT) raw_sql_ + FROM (SELECT ) raw_sql_ WHERE rownum <= 20 ) WHERE raw_rnum_ > 10 @@ -113,8 +117,8 @@ module Arel stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(10) stmt.offset = Nodes::Offset.new(10) - sql = @visitor.accept stmt - sql2 = @visitor.accept stmt + sql = compile stmt + sql2 = compile stmt sql.must_equal sql2 end end @@ -123,7 +127,7 @@ module Arel it 'creates a select from subquery with rownum condition' do stmt = Nodes::SelectStatement.new stmt.offset = Nodes::Offset.new(10) - sql = @visitor.accept stmt + sql = compile stmt sql.must_be_like %{ SELECT * FROM ( SELECT raw_sql_.*, rownum raw_rnum_ @@ -139,7 +143,7 @@ module Arel it 'modified except to be minus' do left = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 10") right = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 20") - sql = @visitor.accept Nodes::Except.new(left, right) + sql = compile Nodes::Except.new(left, right) sql.must_be_like %{ ( SELECT * FROM users WHERE age > 10 MINUS SELECT * FROM users WHERE age > 20 ) } @@ -148,7 +152,7 @@ module Arel 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" + compile(node).must_be_like "FOR UPDATE" end end end |