Skip to content

Commit

Permalink
fixing psych support in big decimal, fixing tests to support YAML 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed May 25, 2011
1 parent 79ed700 commit 929e5c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions activesupport/test/core_ext/bigdecimal_test.rb
Expand Up @@ -4,10 +4,10 @@

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
Expand Down

0 comments on commit 929e5c4

Please sign in to comment.