bigdecimal should be typecast to a float on sqlite3. fixes #2162

This commit is contained in:
Aaron Patterson
2011-07-20 10:44:36 -07:00
parent 993d0f6477
commit 09a488456a
3 changed files with 17 additions and 1 deletions

View File

@@ -157,6 +157,11 @@ module ActiveRecord
end
end
def type_cast(value, column) # :nodoc:
return super unless BigDecimal === value
value.to_f
end
# DATABASE STATEMENTS ======================================

View File

@@ -67,7 +67,7 @@ module ActiveRecord
def test_type_cast_bigdecimal
bd = BigDecimal.new '10.0'
assert_equal bd.to_s('F'), @conn.type_cast(bd, nil)
assert_equal bd.to_f, @conn.type_cast(bd, nil)
end
def test_type_cast_unknown

View File

@@ -1113,6 +1113,17 @@ class BasicsTest < ActiveRecord::TestCase
self.table_name = 'numeric_data'
end
def test_big_decimal_conditions
m = NumericData.new(
:bank_balance => 1586.43,
:big_bank_balance => BigDecimal("1000234000567.95"),
:world_population => 6000000000,
:my_house_population => 3
)
assert m.save
assert_equal 0, NumericData.where("bank_balance > ?", 2000.0).count
end
def test_numeric_fields
m = NumericData.new(
:bank_balance => 1586.43,