mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #13911 from davidcelis/remove-bigdecimal-serialization
Deprecate custom BigDecimal serialization Conflicts: activesupport/CHANGELOG.md
This commit is contained in:
commit
a60ccadbf0
5 changed files with 33 additions and 28 deletions
|
@ -1,6 +1,14 @@
|
|||
* 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*
|
||||
|
|
|
@ -1,22 +1,7 @@
|
|||
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)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
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
|
|
@ -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
|
|
@ -2,18 +2,6 @@ require 'abstract_unit'
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue