aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2010-05-12 01:47:58 -0300
committerJeremy Kemper <jeremy@bitsweat.net>2010-05-11 22:29:26 -0700
commit5f3bd55726703e08ba595555e1cf428c57832603 (patch)
tree2d715460c95d1928ff7abe63af7fdb6b2ad35e21 /activerecord
parent75ddbfecde6452b233540c67b93057f124726638 (diff)
downloadrails-5f3bd55726703e08ba595555e1cf428c57832603.tar.gz
rails-5f3bd55726703e08ba595555e1cf428c57832603.tar.bz2
rails-5f3bd55726703e08ba595555e1cf428c57832603.zip
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>
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb2
-rw-r--r--activerecord/test/cases/calculations_test.rb3
2 files changed, 2 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 858d298470..0e11f89c8b 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -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
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index 28a1ae5feb..8473150338 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -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