Permalink
Browse files

adding better tests surrounding limits in adapter visitors

  • Loading branch information...
tenderlove committed Jan 4, 2011
1 parent ef29263 commit f5e09790550fcb7d413d495be25f8fe74a571850
@@ -25,7 +25,7 @@ def visit_Arel_Nodes_UpdateStatement o
("SET #{o.values.map { |value| visit value }.join ', '}" unless o.values.empty?),
("WHERE #{o.wheres.map { |x| visit x }.join ' AND '}" unless o.wheres.empty?),
("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
- ("LIMIT #{visit o.limit}" if o.limit),
+ (visit(o.limit) if o.limit),
].compact.join ' '
end
@@ -17,7 +17,7 @@ def visit_Arel_Nodes_SelectStatement o
[
"SELECT * FROM (#{sql}) AS id_list",
"ORDER BY #{aliased_orders(o.orders).join(', ')}",
- ("LIMIT #{visit o.limit}" if o.limit),
+ (visit(o.limit) if o.limit),
(visit(o.offset) if o.offset),
].compact.join ' '
else
@@ -19,8 +19,8 @@ module Visitors
it "should escape LIMIT" do
sc = Arel::Nodes::UpdateStatement.new
- sc.limit = "omg"
- assert_match(/LIMIT 'omg'/, @visitor.accept(sc))
+ sc.limit = Nodes::Limit.new("omg")
+ assert_equal("UPDATE NULL LIMIT 'omg'", @visitor.accept(sc))
end
it 'uses DUAL for empty from' do
@@ -15,10 +15,12 @@ module Visitors
it "should escape LIMIT" do
sc = Arel::Nodes::SelectStatement.new
- sc.limit = "omg"
+ sc.limit = Nodes::Limit.new("omg")
sc.cores.first.projections << 'DISTINCT ON'
sc.orders << "xyz"
- assert_match(/LIMIT 'omg'/, @visitor.accept(sc))
+ sql = @visitor.accept(sc)
+ assert_match(/LIMIT 'omg'/, sql)
+ assert_equal 1, sql.scan(/LIMIT/).length, 'should have one limit'
end
end
end

0 comments on commit f5e0979

Please sign in to comment.