Skip to content
This repository
Browse code

prefering psych as the yaml parser if possible, fixing assertions for…

… YAML 1.1 compatibility
  • Loading branch information...
commit f55a1715f817ef0a55426b6527448aced0f5aef1 1 parent 929e5c4
Aaron Patterson authored January 19, 2011
6  activesupport/lib/active_support/core_ext/big_decimal/conversions.rb
... ...
@@ -1,4 +1,10 @@
1 1
 require 'bigdecimal'
  2
+
  3
+begin
  4
+  require 'psych'
  5
+rescue LoadError
  6
+end
  7
+
2 8
 require 'yaml'
3 9
 
4 10
 class BigDecimal
14  activesupport/lib/active_support/time_with_zone.rb
@@ -135,14 +135,20 @@ def as_json(options = nil)
135 135
       end
136 136
     end
137 137
 
138  
-    def to_yaml(options = {})
139  
-      if options.kind_of?(YAML::Emitter)
140  
-        utc.to_yaml(options)
  138
+    def encode_with(coder)
  139
+      if coder.respond_to?(:represent_object)
  140
+        coder.represent_object(nil, utc)
141 141
       else
142  
-        time.to_yaml(options).gsub('Z', formatted_offset(true, 'Z'))
  142
+        coder.represent_scalar(nil, utc.strftime("%Y-%m-%d %H:%M:%S.%9NZ"))
143 143
       end
144 144
     end
145 145
 
  146
+    def to_yaml(options = {})
  147
+      return super if defined?(YAML::ENGINE) && !YAML::ENGINE.syck?
  148
+
  149
+      utc.to_yaml(options)
  150
+    end
  151
+
146 152
     def httpdate
147 153
       utc.httpdate
148 154
     end
4  activesupport/test/core_ext/time_with_zone_test.rb
@@ -106,11 +106,11 @@ def test_xmlschema_with_fractional_seconds
106 106
   end
107 107
 
108 108
   def test_to_yaml
109  
-    assert_equal "--- 1999-12-31 19:00:00 -05:00\n", @twz.to_yaml
  109
+    assert_match(/^--- 2000-01-01 00:00:00(\.0+)?\s*Z\n/, @twz.to_yaml)
110 110
   end
111 111
 
112 112
   def test_ruby_to_yaml
113  
-    assert_equal "--- \n:twz: 2000-01-01 00:00:00 Z\n", {:twz => @twz}.to_yaml
  113
+    assert_match(/---\s*\n:twz: 2000-01-01 00:00:00(\.0+)?\s*Z\n/, {:twz => @twz}.to_yaml)
114 114
   end
115 115
 
116 116
   def test_httpdate

0 notes on commit f55a171

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