diff options
author | Suraj N. Kurapati <sunaku@gmail.com> | 2012-09-21 02:48:20 -0700 |
---|---|---|
committer | Suraj N. Kurapati <sunaku@gmail.com> | 2012-09-21 02:56:40 -0700 |
commit | efdda5030a460e8af58ef0f7f4cd5ce8d7f1b541 (patch) | |
tree | 054cb1b6d3e24b844d59d1139325b62e51523972 /test | |
parent | e032dabdb2adb34e3db8cd35e9f58bc0536475c1 (diff) | |
download | rails-efdda5030a460e8af58ef0f7f4cd5ce8d7f1b541.tar.gz rails-efdda5030a460e8af58ef0f7f4cd5ce8d7f1b541.tar.bz2 rails-efdda5030a460e8af58ef0f7f4cd5ce8d7f1b541.zip |
GH-139: some aggregations lacked DISTINCT emission
Diffstat (limited to 'test')
-rw-r--r-- | test/visitors/test_to_sql.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index 1caedacd45..dfe1d49a4e 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -48,6 +48,45 @@ module Arel sql.must_be_like %{ omg(*) = 2 } end + it 'should visit built-in functions' do + function = Nodes::Count.new([Arel.star]) + assert_equal 'COUNT(*)', @visitor.accept(function) + + function = Nodes::Sum.new([Arel.star]) + assert_equal 'SUM(*)', @visitor.accept(function) + + function = Nodes::Max.new([Arel.star]) + assert_equal 'MAX(*)', @visitor.accept(function) + + function = Nodes::Min.new([Arel.star]) + assert_equal 'MIN(*)', @visitor.accept(function) + + function = Nodes::Avg.new([Arel.star]) + assert_equal 'AVG(*)', @visitor.accept(function) + end + + it 'should visit built-in functions operating on distinct values' do + function = Nodes::Count.new([Arel.star]) + function.distinct = true + assert_equal 'COUNT(DISTINCT *)', @visitor.accept(function) + + function = Nodes::Sum.new([Arel.star]) + function.distinct = true + assert_equal 'SUM(DISTINCT *)', @visitor.accept(function) + + function = Nodes::Max.new([Arel.star]) + function.distinct = true + assert_equal 'MAX(DISTINCT *)', @visitor.accept(function) + + function = Nodes::Min.new([Arel.star]) + function.distinct = true + assert_equal 'MIN(DISTINCT *)', @visitor.accept(function) + + function = Nodes::Avg.new([Arel.star]) + function.distinct = true + assert_equal 'AVG(DISTINCT *)', @visitor.accept(function) + end + it 'works with lists' do function = Nodes::NamedFunction.new('omg', [Arel.star, Arel.star]) assert_equal 'omg(*, *)', @visitor.accept(function) |