mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
bigdecimal should be typecast to a float on sqlite3. fixes #2162
This commit is contained in:
@@ -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 ======================================
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user