diff options
author | Raimo Tuisku <raimo.tuisku@gmail.com> | 2016-04-15 15:27:45 -0700 |
---|---|---|
committer | Raimo Tuisku <raimo.tuisku@gmail.com> | 2016-05-23 20:54:43 -0700 |
commit | 26fe640c9ae644b280b1d01a0d162422995647d6 (patch) | |
tree | 1d93e8d1669ec8808627f9b4c839e4820d72dd54 /activemodel/lib/active_model | |
parent | 7fc4979d4dab63591dcbf75367c496cbfa2881ce (diff) | |
download | rails-26fe640c9ae644b280b1d01a0d162422995647d6.tar.gz rails-26fe640c9ae644b280b1d01a0d162422995647d6.tar.bz2 rails-26fe640c9ae644b280b1d01a0d162422995647d6.zip |
Print the proper ::Float::INFINITY value when used as a default value
Addresses https://github.com/rails/rails/issues/22396
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/type/float.rb | 9 |
1 files changed, 9 insertions, 0 deletions
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 |