提交 9ee65aaa 编写于 作者: R Rafael Mendonça França

Merge pull request #8781 from trisweb/tristan_8757_integer_column_nan_error_fix

Fix error raised when assigning NaN to an integer column
......@@ -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*
......
......@@ -206,11 +206,7 @@ def value_to_integer(value)
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
......
......@@ -57,6 +57,12 @@ def test_type_cast_object_without_to_i_to_integer
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('')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册