mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
fixing psych support in big decimal, fixing tests to support YAML 1.1
This commit is contained in:
@@ -12,12 +12,19 @@ class BigDecimal
|
||||
#
|
||||
# Note that reconstituting YAML floats to native floats may lose precision.
|
||||
def to_yaml(opts = {})
|
||||
return super if defined?(YAML::ENGINE) && !YAML::ENGINE.syck?
|
||||
|
||||
YAML.quick_emit(nil, opts) do |out|
|
||||
string = to_s
|
||||
out.scalar(YAML_TAG, YAML_MAPPING[string] || string, :plain)
|
||||
end
|
||||
end
|
||||
|
||||
def encode_with(coder)
|
||||
string = to_s
|
||||
coder.represent_scalar(nil, YAML_MAPPING[string] || string)
|
||||
end
|
||||
|
||||
def to_d
|
||||
self
|
||||
end
|
||||
|
||||
@@ -4,10 +4,10 @@ require 'active_support/core_ext/big_decimal'
|
||||
|
||||
class BigDecimalTest < Test::Unit::TestCase
|
||||
def test_to_yaml
|
||||
assert_equal("--- 100000.30020320320000000000000000000000000000001\n", BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml)
|
||||
assert_equal("--- .Inf\n", BigDecimal.new('Infinity').to_yaml)
|
||||
assert_equal("--- .NaN\n", BigDecimal.new('NaN').to_yaml)
|
||||
assert_equal("--- -.Inf\n", BigDecimal.new('-Infinity').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
|
||||
|
||||
Reference in New Issue
Block a user