diff options
-rw-r--r-- | lib/arel/nodes/with.rb | 12 | ||||
-rw-r--r-- | lib/arel/select_manager.rb | 32 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 34 | ||||
-rw-r--r-- | test/test_select_manager.rb | 60 |
4 files changed, 69 insertions, 69 deletions
diff --git a/lib/arel/nodes/with.rb b/lib/arel/nodes/with.rb index 0745080cc3..7f08abe47d 100644 --- a/lib/arel/nodes/with.rb +++ b/lib/arel/nodes/with.rb @@ -1,10 +1,10 @@ module Arel - module Nodes - class With < Arel::Nodes::Unary - alias children expr - end + module Nodes + class With < Arel::Nodes::Unary + alias children expr + end - class WithRecursive < With; end - end + class WithRecursive < With; end + end end diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb index 8f5995e32c..4e1382224d 100644 --- a/lib/arel/select_manager.rb +++ b/lib/arel/select_manager.rb @@ -31,7 +31,7 @@ module Arel def where_clauses if $VERBOSE - warn "(#{caller.first}) where_clauses is deprecated and will be removed in arel 3.0.0 with no replacement" + warn "(#{caller.first}) where_clauses is deprecated and will be removed in arel 3.0.0 with no replacement" end to_sql = Visitors::ToSql.new @engine @ctx.wheres.map { |c| to_sql.accept c } @@ -135,24 +135,24 @@ module Arel end def union operation, other = nil - if operation.is_a? Symbol - node_class = Nodes.const_get("Union#{operation.to_s.capitalize}") - else - other = operation - node_class = Nodes::Union - end + if operation.is_a? Symbol + node_class = Nodes.const_get("Union#{operation.to_s.capitalize}") + else + other = operation + node_class = Nodes::Union + end - node_class.new self.ast, other.ast - end + node_class.new self.ast, other.ast + end def with *subqueries - if subqueries.first.is_a? Symbol - node_class = Nodes.const_get("With#{subqueries.shift.to_s.capitalize}") - else - node_class = Nodes::With - end - @ast.with = node_class.new(subqueries.flatten) - end + if subqueries.first.is_a? Symbol + node_class = Nodes.const_get("With#{subqueries.shift.to_s.capitalize}") + else + node_class = Nodes::With + end + @ast.with = node_class.new(subqueries.flatten) + end def take limit @ast.limit = Nodes::Limit.new(limit) diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index e021b5a707..7cb4213fbb 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -48,7 +48,7 @@ module Arel (#{caller.first}) Using UpdateManager without setting UpdateManager#key is deprecated and support will be removed in ARel 3.0.0. Please set the primary key on UpdateManager using UpdateManager#key= -eowarn + eowarn key = o.relation.primary_key end @@ -75,8 +75,8 @@ eowarn "INSERT INTO #{visit o.relation}", ("(#{o.columns.map { |x| - quote_column_name x.name - }.join ', '})" unless o.columns.empty?), + quote_column_name x.name + }.join ', '})" unless o.columns.empty?), (visit o.values if o.values), ].compact.join ' ' @@ -129,7 +129,7 @@ eowarn def visit_Arel_Nodes_SelectStatement o [ - (visit(o.with) if o.with), + (visit(o.with) if o.with), o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join, ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?), (visit(o.limit) if o.limit), @@ -151,20 +151,20 @@ eowarn end def visit_Arel_Nodes_With o - "WITH #{o.children.map { |x| visit x }.join(', ')}" - end + "WITH #{o.children.map { |x| visit x }.join(', ')}" + end - def visit_Arel_Nodes_WithRecursive o - "WITH RECURSIVE #{o.children.map { |x| visit x }.join(', ')}" - end + def visit_Arel_Nodes_WithRecursive o + "WITH RECURSIVE #{o.children.map { |x| visit x }.join(', ')}" + end - def visit_Arel_Nodes_Union o - "( #{visit o.left} UNION #{visit o.right} )" - end + def visit_Arel_Nodes_Union o + "( #{visit o.left} UNION #{visit o.right} )" + end - def visit_Arel_Nodes_UnionAll o - "( #{visit o.left} UNION ALL #{visit o.right} )" - end + def visit_Arel_Nodes_UnionAll o + "( #{visit o.left} UNION ALL #{visit o.right} )" + end def visit_Arel_Nodes_Having o "HAVING #{visit o.expr}" @@ -303,11 +303,11 @@ eowarn end def visit_Arel_Nodes_In o - "#{visit o.left} IN (#{visit o.right})" + "#{visit o.left} IN (#{visit o.right})" end def visit_Arel_Nodes_NotIn o - "#{visit o.left} NOT IN (#{visit o.right})" + "#{visit o.left} NOT IN (#{visit o.right})" end def visit_Arel_Nodes_And o diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb index f2873b2a65..bd96345b01 100644 --- a/test/test_select_manager.rb +++ b/test/test_select_manager.rb @@ -48,9 +48,9 @@ module Arel describe 'select manager' do def test_join_sources - manager = Arel::SelectManager.new Table.engine - manager.join_sources << Arel::Nodes::StringJoin.new('foo') - assert_equal "SELECT FROM 'foo'", manager.to_sql + manager = Arel::SelectManager.new Table.engine + manager.join_sources << Arel::Nodes::StringJoin.new('foo') + assert_equal "SELECT FROM 'foo'", manager.to_sql end describe 'backwards compatibility' do @@ -179,41 +179,41 @@ module Arel end describe 'union' do - before do - table = Table.new :users - @m1 = Arel::SelectManager.new Table.engine, table - @m1.project Arel.star - @m1.where(table[:age].lt(18)) + before do + table = Table.new :users + @m1 = Arel::SelectManager.new Table.engine, table + @m1.project Arel.star + @m1.where(table[:age].lt(18)) - @m2 = Arel::SelectManager.new Table.engine, table - @m2.project Arel.star - @m2.where(table[:age].gt(99)) + @m2 = Arel::SelectManager.new Table.engine, table + @m2.project Arel.star + @m2.where(table[:age].gt(99)) - end + end - it 'should union two managers' do - # FIXME should this union "managers" or "statements" ? - # FIXME this probably shouldn't return a node - node = @m1.union @m2 + it 'should union two managers' do + # FIXME should this union "managers" or "statements" ? + # FIXME this probably shouldn't return a node + node = @m1.union @m2 - # maybe FIXME: decide when wrapper parens are needed - node.to_sql.must_be_like %{ - ( SELECT * FROM "users" WHERE "users"."age" < 18 UNION SELECT * FROM "users" WHERE "users"."age" > 99 ) - } - end + # maybe FIXME: decide when wrapper parens are needed + node.to_sql.must_be_like %{ + ( SELECT * FROM "users" WHERE "users"."age" < 18 UNION SELECT * FROM "users" WHERE "users"."age" > 99 ) + } + end - it 'should union all' do - node = @m1.union :all, @m2 + it 'should union all' do + node = @m1.union :all, @m2 - node.to_sql.must_be_like %{ - ( SELECT * FROM "users" WHERE "users"."age" < 18 UNION ALL SELECT * FROM "users" WHERE "users"."age" > 99 ) - } - end + node.to_sql.must_be_like %{ + ( SELECT * FROM "users" WHERE "users"."age" < 18 UNION ALL SELECT * FROM "users" WHERE "users"."age" > 99 ) + } + end - end + end - describe 'with' do + describe 'with' do it "should support WITH RECURSIVE" do comments = Table.new(:comments) @@ -249,7 +249,7 @@ module Arel } end - end + end describe 'ast' do it 'should return the ast' do |