diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-24 13:56:37 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-24 13:56:37 -0700 |
commit | aa6a82617178698f4f5083cc8ba08d2f761583af (patch) | |
tree | 88794af81a74f9d61cb87814f0c895bf4cc6ded2 /spec/arel | |
parent | d94122485a8f89f13293438142fa292640600c54 (diff) | |
download | rails-aa6a82617178698f4f5083cc8ba08d2f761583af.tar.gz rails-aa6a82617178698f4f5083cc8ba08d2f761583af.tar.bz2 rails-aa6a82617178698f4f5083cc8ba08d2f761583af.zip |
avoid modifying the ast in certain cases
Diffstat (limited to 'spec/arel')
-rw-r--r-- | spec/arel/visitors/oracle_spec.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/arel/visitors/oracle_spec.rb b/spec/arel/visitors/oracle_spec.rb index 0995ea6bf2..784f4b24e1 100644 --- a/spec/arel/visitors/oracle_spec.rb +++ b/spec/arel/visitors/oracle_spec.rb @@ -19,6 +19,18 @@ module Arel } end + it 'is idempotent with crazy query' 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) + sql2 = @visitor.accept(stmt) + check sql.should == sql2 + end + describe 'Nodes::SelectStatement' do describe 'limit' do it 'adds a rownum clause' do @@ -28,6 +40,15 @@ module Arel sql.should be_like %{ SELECT WHERE ROWNUM <= 10 } end + it 'is idempotent' do + stmt = Nodes::SelectStatement.new + stmt.orders << Nodes::SqlLiteral.new('foo') + stmt.limit = 10 + sql = @visitor.accept stmt + sql2 = @visitor.accept stmt + check sql.should == sql2 + end + it 'creates a subquery when there is order_by' do stmt = Nodes::SelectStatement.new stmt.orders << Nodes::SqlLiteral.new('foo') @@ -52,6 +73,15 @@ module Arel WHERE raw_rnum_ > 10 } end + + it 'is idempotent with different subquery' do + stmt = Nodes::SelectStatement.new + stmt.limit = 10 + stmt.offset = Nodes::Offset.new(10) + sql = @visitor.accept stmt + sql2 = @visitor.accept stmt + check sql.should == sql2 + end end end end |