From 26fe640c9ae644b280b1d01a0d162422995647d6 Mon Sep 17 00:00:00 2001 From: Raimo Tuisku Date: Fri, 15 Apr 2016 15:27:45 -0700 Subject: Print the proper ::Float::INFINITY value when used as a default value Addresses https://github.com/rails/rails/issues/22396 --- activemodel/lib/active_model/type/float.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/type/float.rb b/activemodel/lib/active_model/type/float.rb index 0f925bc7e1..4c128eea01 100644 --- a/activemodel/lib/active_model/type/float.rb +++ b/activemodel/lib/active_model/type/float.rb @@ -7,6 +7,15 @@ module ActiveModel :float end + def type_cast_for_schema(value) + return "::Float::NAN" if value.try(:nan?) + case value + when ::Float::INFINITY then "::Float::INFINITY" + when -::Float::INFINITY then "-::Float::INFINITY" + else super + end + end + alias serialize cast private -- cgit v1.2.3