Skip to content
This repository
Browse code

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
Santiago Pastorino authored May 12, 2010 jeremy committed May 11, 2010
2  activerecord/lib/active_record/calculations.rb
@@ -298,7 +298,7 @@ def type_cast_calculated_value(value, column, operation = nil)
298 298
             case operation.to_s.downcase
299 299
             when 'count' then value.to_i
300 300
             when 'sum'   then type_cast_using_column(value || '0', column)
301  
-            when 'avg' then value && (value.is_a?(Fixnum) ? value.to_f : value).to_d
  301
+            when 'avg' then value.try(:to_d)
302 302
             else type_cast_using_column(value, column)
303 303
             end
304 304
           else
3  activerecord/test/cases/calculations_test.rb
@@ -23,8 +23,7 @@ def test_should_sum_field
23 23
 
24 24
   def test_should_average_field
25 25
     value = Account.average(:credit_limit)
26  
-    assert_kind_of BigDecimal, value
27  
-    assert_equal BigDecimal.new('53.0'), value
  26
+    assert_equal 53.0, value
28 27
   end
29 28
 
30 29
   def test_should_return_nil_as_average

0 notes on commit ad73a3a

Please sign in to comment.
Something went wrong with that request. Please try again.