From 9c9c950d02af83742a5f76302d0faa99508f242c Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Thu, 21 Feb 2019 13:10:14 +0900 Subject: [PATCH] Revert "Speed up integer casting from DB" This reverts commit 52fddcc653458456f98b3683dffd781cf00b35fe. 52fddcc was to short-circuit `ensure_in_range` in `cast_value`. But that caused a regression for empty string deserialization. Since 7c6f393, `ensure_in_range` is moved into `serialize`. As 52fddcc said, the absolute gain is quite small. So I've reverted that commit to fix the regression. --- activemodel/lib/active_model/type/integer.rb | 5 ----- activemodel/test/cases/type/integer_test.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/activemodel/lib/active_model/type/integer.rb b/activemodel/lib/active_model/type/integer.rb index 5878b9417175d..1ff232a977d0c 100644 --- a/activemodel/lib/active_model/type/integer.rb +++ b/activemodel/lib/active_model/type/integer.rb @@ -18,11 +18,6 @@ def type :integer end - def deserialize(value) - return if value.nil? - value.to_i - end - def serialize(value) result = super if result diff --git a/activemodel/test/cases/type/integer_test.rb b/activemodel/test/cases/type/integer_test.rb index 9bd0110099915..dec188b4cca40 100644 --- a/activemodel/test/cases/type/integer_test.rb +++ b/activemodel/test/cases/type/integer_test.rb @@ -54,7 +54,7 @@ class IntegerTest < ActiveModel::TestCase type = Type::Integer.new assert_nil type.cast("") assert_nil type.serialize("") - assert_equal 0, type.deserialize("") + assert_nil type.deserialize("") end test "changed?" do