diff options
author | Tristan Harward <trisweb@gmail.com> | 2013-01-06 15:39:09 -0500 |
---|---|---|
committer | Tristan Harward <trisweb@gmail.com> | 2013-01-06 16:09:40 -0500 |
commit | 807e176aba7804cad8d630d04f3b771011be4fe6 (patch) | |
tree | b10a9346cf09ecf9c29c55075e201b4da96edc68 /activerecord/test | |
parent | 85afc11756630eb8d4bdc302ea026834251ffc8a (diff) | |
download | rails-807e176aba7804cad8d630d04f3b771011be4fe6.tar.gz rails-807e176aba7804cad8d630d04f3b771011be4fe6.tar.bz2 rails-807e176aba7804cad8d630d04f3b771011be4fe6.zip |
Fix error when assigning NaN to an integer column
Also covers any non-castable case by returning nil, which
is in-line with the intention of the former implementation,
but covers the odd cases which respond to to_i but raise
an error when it's called, such as NaN, Infinity and -Infinity.
Fixes #8757
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/column_test.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/column_test.rb b/activerecord/test/cases/column_test.rb index dc1b30261c..adbe51f430 100644 --- a/activerecord/test/cases/column_test.rb +++ b/activerecord/test/cases/column_test.rb @@ -57,6 +57,12 @@ module ActiveRecord assert_nil column.type_cast(Object.new) end + def test_type_cast_nan_and_infinity_to_integer + column = Column.new("field", nil, "integer") + assert_nil column.type_cast(Float::NAN) + assert_nil column.type_cast(1.0/0.0) + end + def test_type_cast_time column = Column.new("field", nil, "time") assert_equal nil, column.type_cast('') |