mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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:
parent
75ddbfecde
commit
5f3bd55726
2 changed files with 2 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue