diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-19 15:19:57 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-21 11:16:40 -0800 |
commit | 7642b7531d222c9d7a94add50fffca69458e0eef (patch) | |
tree | 9e22e5e921f344c888bad2217b4e25a2d4f91538 | |
parent | 2570c85cb7de03a2c9cc183c73707a267f2efb91 (diff) | |
download | rails-7642b7531d222c9d7a94add50fffca69458e0eef.tar.gz rails-7642b7531d222c9d7a94add50fffca69458e0eef.tar.bz2 rails-7642b7531d222c9d7a94add50fffca69458e0eef.zip |
prefering psych as the yaml parser if possible, fixing assertions for YAML 1.1 compatibility
3 files changed, 18 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb index a279849829..11c318c244 100644 --- a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb +++ b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb @@ -1,4 +1,10 @@ require 'bigdecimal' + +begin + require 'psych' +rescue LoadError +end + require 'yaml' class BigDecimal diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 8137f8e17e..3da216ac78 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -137,7 +137,17 @@ module ActiveSupport end end + def encode_with(coder) + if coder.respond_to?(:represent_object) + coder.represent_object(nil, utc) + else + coder.represent_scalar(nil, utc.strftime("%Y-%m-%d %H:%M:%S.%9NZ")) + end + end + def to_yaml(options = {}) + return super if defined?(YAML::ENGINE) && !YAML::ENGINE.syck? + utc.to_yaml(options) end diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 2b86da67fa..5c226c2d09 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -106,11 +106,11 @@ class TimeWithZoneTest < Test::Unit::TestCase end def test_to_yaml - assert_equal "--- 2000-01-01 00:00:00 Z\n", @twz.to_yaml + assert_match(/^--- 2000-01-01 00:00:00(\.0+)?\s*Z\n/, @twz.to_yaml) end def test_ruby_to_yaml - assert_equal "--- \n:twz: 2000-01-01 00:00:00 Z\n", {:twz => @twz}.to_yaml + assert_match(/---\s*\n:twz: 2000-01-01 00:00:00(\.0+)?\s*Z\n/, {:twz => @twz}.to_yaml) end def test_httpdate |