Skip to content

Commit

Permalink
prefering psych as the yaml parser if possible, fixing assertions for…
Browse files Browse the repository at this point in the history
… YAML 1.1 compatibility
  • Loading branch information
tenderlove committed Jan 21, 2011
1 parent 2570c85 commit 7642b75
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
@@ -1,4 +1,10 @@
require 'bigdecimal'

begin
require 'psych'
rescue LoadError
end

require 'yaml'

class BigDecimal
Expand Down
10 changes: 10 additions & 0 deletions activesupport/lib/active_support/time_with_zone.rb
Expand Up @@ -137,7 +137,17 @@ def as_json(options = nil)
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

Expand Down
4 changes: 2 additions & 2 deletions activesupport/test/core_ext/time_with_zone_test.rb
Expand Up @@ -106,11 +106,11 @@ def test_xmlschema_with_fractional_seconds
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
Expand Down

0 comments on commit 7642b75

Please sign in to comment.