aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/calculations_test.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-03-14 14:59:14 +0000
committerRick Olson <technoweenie@gmail.com>2006-03-14 14:59:14 +0000
commit796a43dead8ebf2fb9d28a25cb90e83c9baab4a0 (patch)
treee42b0751747544e5a14d2916ee51205173d586cd /activerecord/test/calculations_test.rb
parentc6abe81b1eebd741b2a36e6618bf6f1c07b87588 (diff)
downloadrails-796a43dead8ebf2fb9d28a25cb90e83c9baab4a0.tar.gz
rails-796a43dead8ebf2fb9d28a25cb90e83c9baab4a0.tar.bz2
rails-796a43dead8ebf2fb9d28a25cb90e83c9baab4a0.zip
Allow ordering of calculated results and/or grouped fields in calculations [solo@gatelys.com] closes #4228
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3865 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/calculations_test.rb')
-rw-r--r--activerecord/test/calculations_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/calculations_test.rb b/activerecord/test/calculations_test.rb
index e724695406..8f4a3de17a 100644
--- a/activerecord/test/calculations_test.rb
+++ b/activerecord/test/calculations_test.rb
@@ -37,6 +37,17 @@ class CalculationsTest < Test::Unit::TestCase
assert_equal 60, c[2]
end
+ def test_should_order_by_grouped_field
+ c = Account.sum(:credit_limit, :group => :firm_id, :order => "firm_id")
+ assert_equal [nil, 1, 2, 6], c.keys
+ end
+
+ def test_should_order_by_calculation
+ c = Account.sum(:credit_limit, :group => :firm_id, :order => "sum_credit_limit desc, firm_id")
+ assert_equal [105, 60, 50, 50], c.keys.collect { |k| c[k] }
+ assert_equal [6, 2, nil, 1], c.keys
+ end
+
def test_should_group_by_summed_field_having_condition
c = Account.sum(:credit_limit, :group => :firm_id,
:having => 'sum(credit_limit) > 50')