aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/type
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-10-04 17:37:04 -0400
committerGitHub <noreply@github.com>2016-10-04 17:37:04 -0400
commitde9a56b66af928a09f85daf15ffb1c2023a7c1b8 (patch)
treef3ec18064c3b14d3b8448b3a35e0e69550bac67c /activemodel/lib/active_model/type
parent4d6feef79248a63c4cefde3f9ceb2242925e8d8d (diff)
parent26fe640c9ae644b280b1d01a0d162422995647d6 (diff)
downloadrails-de9a56b66af928a09f85daf15ffb1c2023a7c1b8.tar.gz
rails-de9a56b66af928a09f85daf15ffb1c2023a7c1b8.tar.bz2
rails-de9a56b66af928a09f85daf15ffb1c2023a7c1b8.zip
Merge pull request #24571 from raimo/patch-1
Print the proper ::Float::INFINITY value when used as a default value
Diffstat (limited to 'activemodel/lib/active_model/type')
-rw-r--r--activemodel/lib/active_model/type/float.rb9
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 94bb7e700c..4d0d2771a0 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