aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/safe_buffer_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test/safe_buffer_test.rb')
-rw-r--r--activesupport/test/safe_buffer_test.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb
index bf61f9e58c..a4e2acbb32 100644
--- a/activesupport/test/safe_buffer_test.rb
+++ b/activesupport/test/safe_buffer_test.rb
@@ -1,4 +1,10 @@
require 'abstract_unit'
+begin
+ require 'psych'
+rescue LoadError
+end
+
+require 'yaml'
class SafeBufferTest < ActiveSupport::TestCase
def setup
@@ -38,4 +44,20 @@ class SafeBufferTest < ActiveSupport::TestCase
new_buffer = @buffer.to_s
assert_equal ActiveSupport::SafeBuffer, new_buffer.class
end
+
+ def test_to_yaml
+ str = 'hello!'
+ buf = ActiveSupport::SafeBuffer.new str
+ yaml = buf.to_yaml
+
+ assert_match(/^--- #{str}/, yaml)
+ assert_equal 'hello!', YAML.load(yaml)
+ end
+
+ def test_nested
+ str = 'hello!'
+ data = { 'str' => ActiveSupport::SafeBuffer.new(str) }
+ yaml = YAML.dump data
+ assert_equal({'str' => str}, YAML.load(yaml))
+ end
end