Skip to content
Browse files

fixing psych support in big decimal, fixing tests to support YAML 1.1

  • Loading branch information...
1 parent 79ed700 commit 929e5c40f47a4ff012c1f3a1e4abd50a0451df1e @tenderlove tenderlove committed
View
7 activesupport/lib/active_support/core_ext/big_decimal/conversions.rb
@@ -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
View
8 activesupport/test/core_ext/bigdecimal_test.rb
@@ -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

0 comments on commit 929e5c4

Please sign in to comment.
Something went wrong with that request. Please try again.