From 93be7d560b2eb42465f079f7f75e786fa8ed1d09 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 12 May 2010 01:47:58 -0300 Subject: [PATCH 1/2] SQLite returns Float [#4514 state:committed] --- activerecord/test/cases/calculations_test.rb | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 28a1ae5..efecdb4 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -20,8 +20,12 @@ 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 + if current_adapter?(:SQLiteAdapter) + assert_kind_of Float, value + else + assert_kind_of BigDecimal, value + end + assert_equal 53.0, value end def test_should_return_nil_as_average -- 1.7.1 From 9bf0727c79de694f98347d26787332b461da5894 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 12 May 2010 01:48:49 -0300 Subject: [PATCH 2/2] type_cast_calculated_value refactor value is never a Fixnum here --- .../lib/active_record/relation/calculations.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 858d298..0e11f89 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 -- 1.7.1