type_cast_calculated_value refactor: value is never a Fixnum here. Fix test since SQLite returns Float.

[#4514 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
Santiago Pastorino 2010-05-12 01:47:58 -03:00 committed by Jeremy Kemper
parent 75ddbfecde
commit 5f3bd55726
2 changed files with 2 additions and 3 deletions

View File

@ -243,7 +243,7 @@ module ActiveRecord
case operation
when 'count' then value.to_i
when 'sum' then type_cast_using_column(value || '0', column)
when 'average' then value && (value.is_a?(Fixnum) ? value.to_f : value).to_d
when 'average' then value.try(:to_d)
else type_cast_using_column(value, column)
end
else

View File

@ -20,8 +20,7 @@ class CalculationsTest < ActiveRecord::TestCase
def test_should_average_field
value = Account.average(:credit_limit)
assert_kind_of BigDecimal, value
assert_equal BigDecimal.new('53.0'), value
assert_equal 53.0, value
end
def test_should_return_nil_as_average