diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-01-06 13:15:56 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-01-06 13:15:56 -0800 |
commit | 9ee65aaaadfe40b0cd816e6665419cf55888f38e (patch) | |
tree | b10a9346cf09ecf9c29c55075e201b4da96edc68 | |
parent | 85afc11756630eb8d4bdc302ea026834251ffc8a (diff) | |
parent | 807e176aba7804cad8d630d04f3b771011be4fe6 (diff) | |
download | rails-9ee65aaaadfe40b0cd816e6665419cf55888f38e.tar.gz rails-9ee65aaaadfe40b0cd816e6665419cf55888f38e.tar.bz2 rails-9ee65aaaadfe40b0cd816e6665419cf55888f38e.zip |
Merge pull request #8781 from trisweb/tristan_8757_integer_column_nan_error_fix
Fix error raised when assigning NaN to an integer column
-rw-r--r-- | activerecord/CHANGELOG.md | 9 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/column.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/column_test.rb | 6 |
3 files changed, 12 insertions, 9 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 3a0af57f64..f098c49136 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -4,10 +4,11 @@ *Rob Worley* -* Fix undefined method `to_i` when calling `new` on a scope that uses an Array. - Fixes #8718, #8734. +* Fix undefined method `to_i` when calling `new` on a scope that uses an + Array; Fix FloatDomainError when setting integer column to NaN. + Fixes #8718, #8734, #8757. - *Jason Stirk* + *Jason Stirk + Tristan Harward* * Rename `update_attributes` to `update`, keep `update_attributes` as an alias for `update` method. This is a soft-deprecation for `update_attributes`, although it will still work without any @@ -17,7 +18,7 @@ *Amparo Luna + Guillermo Iguaran* * `after_commit` and `after_rollback` now validate the `:on` option and raise an `ArgumentError` - if it is not one of `:create`, `:destroy` or ``:update` + if it is not one of `:create`, `:destroy` or `:update` *Pascal Friederich* diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index 51d3acaff8..fb28ecb6cf 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -206,11 +206,7 @@ module ActiveRecord when TrueClass, FalseClass value ? 1 : 0 else - if value.respond_to?(:to_i) - value.to_i - else - nil - end + value.to_i rescue nil end end 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('') |