提交 a60ccadb 编写于 作者: R Rafael Mendonça França

Merge pull request #13911 from davidcelis/remove-bigdecimal-serialization

Deprecate custom BigDecimal serialization

Conflicts:
	activesupport/CHANGELOG.md
* Deprecate custom `BigDecimal` serialization
Deprecate the custom `BigDecimal` serialization that is included when requiring
`active_support/all` as a fix for #12467. Let Ruby handle YAML serialization
for `BigDecimal` instead.
*David Celis*
* Fix parsing bugs in `XmlMini`
Symbols or boolean parsing would raise an error for non string values (e.g.
Symbols or boolean parsing would raise an error for non string values (e.g.
integers). Decimal parsing would fail due to a missing requirement.
*Birkir A. Barkarson*
......
require 'bigdecimal'
require 'bigdecimal/util'
require 'yaml'
class BigDecimal
YAML_MAPPING = { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' }
def encode_with(coder)
string = to_s
coder.represent_scalar(nil, YAML_MAPPING[string] || string)
end
# Backport this method if it doesn't exist
unless method_defined?(:to_d)
def to_d
self
end
end
DEFAULT_STRING_FORMAT = 'F'
def to_formatted_s(*args)
if args[0].is_a?(Symbol)
......
ActiveSupport::Deprecation.warn 'core_ext/big_decimal/yaml_conversions is deprecated and will be removed in the future.'
require 'bigdecimal'
require 'yaml'
class BigDecimal
YAML_MAPPING = { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' }
def encode_with(coder)
string = to_s
coder.represent_scalar(nil, YAML_MAPPING[string] || string)
end
end
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
......@@ -2,18 +2,6 @@
require 'active_support/core_ext/big_decimal'
class BigDecimalTest < 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
def test_to_d
bd = BigDecimal.new '10'
assert_equal bd, bd.to_d
end
def test_to_s
bd = BigDecimal.new '0.01'
assert_equal '0.01', bd.to_s
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册