Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

type_cast_calculated_value refactor: value is never a Fixnum here. Fi…

…x test since SQLite returns Float.

[#4514 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit ad73a3aec4665d8a44060640e51075fd732c33a1 1 parent 8e679f1
@spastorino spastorino authored jeremy committed
View
2  activerecord/lib/active_record/calculations.rb
@@ -298,7 +298,7 @@ def type_cast_calculated_value(value, column, operation = nil)
case operation.to_s.downcase
when 'count' then value.to_i
when 'sum' then type_cast_using_column(value || '0', column)
- when 'avg' then value && (value.is_a?(Fixnum) ? value.to_f : value).to_d
+ when 'avg' then value.try(:to_d)
else type_cast_using_column(value, column)
end
else
View
3  activerecord/test/cases/calculations_test.rb
@@ -23,8 +23,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
Please sign in to comment.
Something went wrong with that request. Please try again.