diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-07-20 10:44:36 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-07-20 14:39:01 -0700 |
commit | 09a488456aecf2b4ef7f200546b281cabda56e2f (patch) | |
tree | 84c0d478916d97b2a17e1d45e0760c734600e304 | |
parent | 993d0f6477c6dce4eb207578c1d0970cec859447 (diff) | |
download | rails-09a488456aecf2b4ef7f200546b281cabda56e2f.tar.gz rails-09a488456aecf2b4ef7f200546b281cabda56e2f.tar.bz2 rails-09a488456aecf2b4ef7f200546b281cabda56e2f.zip |
bigdecimal should be typecast to a float on sqlite3. fixes #2162
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/sqlite3/quoting_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/base_test.rb | 11 |
3 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 724b2e6d9c..e2a0f63393 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -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 ====================================== diff --git a/activerecord/test/cases/adapters/sqlite3/quoting_test.rb b/activerecord/test/cases/adapters/sqlite3/quoting_test.rb index 0d9db92447..e0152e7ccf 100644 --- a/activerecord/test/cases/adapters/sqlite3/quoting_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/quoting_test.rb @@ -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 diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 8144f7075d..607c87beec 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -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, |