diff options
author | Alexandru Catighera <acatighera@gmail.com> | 2010-11-15 21:33:21 -0500 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-16 10:38:47 -0800 |
commit | a5cdf0b9eb860c4370ae5fde231e1b61f71b6b65 (patch) | |
tree | 35a01126dba80283440ef8a9e5a4af64c6027b8e /activerecord/test | |
parent | 254b0a4bbb5e21fe3c48ac826caec025fcaeffb5 (diff) | |
download | rails-a5cdf0b9eb860c4370ae5fde231e1b61f71b6b65.tar.gz rails-a5cdf0b9eb860c4370ae5fde231e1b61f71b6b65.tar.bz2 rails-a5cdf0b9eb860c4370ae5fde231e1b61f71b6b65.zip |
Fix ActiveRecord calculations when grouped by multiple fields
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/calculations_test.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 61fbf01a50..5cb8485b4b 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -54,6 +54,19 @@ class CalculationsTest < ActiveRecord::TestCase c = Account.sum(:credit_limit, :group => :firm_id) [1,6,2].each { |firm_id| assert c.keys.include?(firm_id) } end + + def test_should_group_by_multiple_fields + c = Account.count(:all, :group => ['firm_id', :credit_limit]) + [ [nil, 50], [1, 50], [6, 50], [6, 55], [9, 53], [2, 60] ].each { |firm_and_limit| assert c.keys.include?(firm_and_limit) } + end + + def test_should_group_by_multiple_fields_having_functions + c = Topic.group(:author_name, 'COALESCE(type, title)').count(:all) + assert_equal 1, c[["Carl", "The Third Topic of the day"]] + assert_equal 1, c[["Mary", "Reply"]] + assert_equal 1, c[["David", "The First Topic"]] + assert_equal 1, c[["Carl", "Reply"]] + end def test_should_group_by_summed_field c = Account.sum(:credit_limit, :group => :firm_id) |