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/lib/active_record/connection_adapters/column.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'activerecord/lib/active_record') 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 -- cgit v1.2.3