From 807e176aba7804cad8d630d04f3b771011be4fe6 Mon Sep 17 00:00:00 2001 From: Tristan Harward Date: Sun, 6 Jan 2013 15:39:09 -0500 Subject: 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 --- activerecord/test/cases/column_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activerecord/test') 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('') -- cgit v1.2.3