Skip to content

Commit

Permalink
type_cast_calculated_value refactor: value is never a Fixnum here. Fi…
Browse files Browse the repository at this point in the history
…x test since SQLite returns Float.

[#4514 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
spastorino authored and jeremy committed May 12, 2010
1 parent 75ddbfe commit 5f3bd55
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation/calculations.rb
Expand Up @@ -243,7 +243,7 @@ def type_cast_calculated_value(value, column, operation = nil)
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
Expand Down
3 changes: 1 addition & 2 deletions activerecord/test/cases/calculations_test.rb
Expand Up @@ -20,8 +20,7 @@ def test_should_sum_field

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
Expand Down

0 comments on commit 5f3bd55

Please sign in to comment.