From 2a38fd58a91a300da5acfe917e82ac681dbd5b50 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 16 May 2012 14:07:10 -0700 Subject: MySQL returns "SUM(DISTINCT(credit_limit))" as the column name unless an alias is provided. Without the alias, the column cannot be found and properly typecast. --- activerecord/test/cases/calculations_test.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases/calculations_test.rb') diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index f8bd11e3d0..041f8ffb7c 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -470,7 +470,11 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal [50, 53, 55, 60], Account.pluck('DISTINCT credit_limit').sort assert_equal [50, 53, 55, 60], Account.pluck('DISTINCT accounts.credit_limit').sort assert_equal [50, 53, 55, 60], Account.pluck('DISTINCT(credit_limit)').sort - assert_equal [50 + 53 + 55 + 60], Account.pluck('SUM(DISTINCT(credit_limit))') + + # MySQL returns "SUM(DISTINCT(credit_limit))" as the column name unless + # an alias is provided. Without the alias, the column cannot be found + # and properly typecast. + assert_equal [50 + 53 + 55 + 60], Account.pluck('SUM(DISTINCT(credit_limit)) as credit_limit') end def test_pluck_expects_a_single_selection -- cgit v1.2.3