aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/big_decimal
diff options
context:
space:
mode:
authorDavid Celis <me@davidcel.is>2014-01-31 17:42:21 -0800
committerDavid Celis <me@davidcel.is>2014-02-01 10:45:51 -0800
commit85d820b1693a52faddf1f838512e132906272e41 (patch)
tree451e75dd1fe30610566906d8e94f64d3e5c6782c /activesupport/test/core_ext/big_decimal
parent9b2a017aa82f95911280ed597e4bf3193c9399e9 (diff)
downloadrails-85d820b1693a52faddf1f838512e132906272e41.tar.gz
rails-85d820b1693a52faddf1f838512e132906272e41.tar.bz2
rails-85d820b1693a52faddf1f838512e132906272e41.zip
Don't require BigDecimal serialization extension
Rails currently provides an extension to BigDecimal that redefines how it is serialized to YAML. However, as noted in #12467, this does not work as expected. When ActiveSupport is required, BigDecimal YAML serialization does not maintain the object type. It instead ends up serializing the number represented by the BigDecimal itself which, when loaded by YAML later, becomes a Float: ```ruby require 'yaml' require 'bigdecimal' yaml = BigDecimal('13.37').to_yaml YAML.load(yaml).class require 'active_support/all' yaml = BigDecimal('13.37').to_yaml YAML.load(yaml).class ``` @tenderlove posits that we should deprecate the custom BigDecimal serialization and let Ruby handle it. For the time being, users who require this serialization for backwards compatibility can manually `require 'active_support/core_ext/big_decimal/yaml_conversions'`. This will close #12467 and deprecate the custom BigDecimal#to_yaml. Signed-off-by: David Celis <me@davidcel.is>
Diffstat (limited to 'activesupport/test/core_ext/big_decimal')
-rw-r--r--activesupport/test/core_ext/big_decimal/yaml_conversions_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/big_decimal/yaml_conversions_test.rb b/activesupport/test/core_ext/big_decimal/yaml_conversions_test.rb
new file mode 100644
index 0000000000..49020e0567
--- /dev/null
+++ b/activesupport/test/core_ext/big_decimal/yaml_conversions_test.rb
@@ -0,0 +1,11 @@
+require 'abstract_unit'
+require 'active_support/core_ext/big_decimal/yaml_conversions'
+
+class BigDecimalYamlConversionsTest < ActiveSupport::TestCase
+ def test_to_yaml
+ assert_match("--- 100000.30020320320000000000000000000000000000001\n", BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml)
+ assert_match("--- .Inf\n", BigDecimal.new('Infinity').to_yaml)
+ assert_match("--- .NaN\n", BigDecimal.new('NaN').to_yaml)
+ assert_match("--- -.Inf\n", BigDecimal.new('-Infinity').to_yaml)
+ end
+end