make sure we play nicely when syck is activated
This commit is contained in:
parent
eb33bd944d
commit
c87fb22a06
@ -1,6 +1,5 @@
|
||||
require 'erb'
|
||||
require 'active_support/core_ext/kernel/singleton_class'
|
||||
require 'active_support/core_ext/yaml'
|
||||
|
||||
class ERB
|
||||
module Util
|
||||
@ -102,10 +101,14 @@ def to_s
|
||||
self
|
||||
end
|
||||
|
||||
unless defined?(Psych)
|
||||
def to_yaml(*args)
|
||||
to_str.to_yaml(*args)
|
||||
end
|
||||
def encode_with(coder)
|
||||
coder.represent_scalar nil, to_str
|
||||
end
|
||||
|
||||
def to_yaml(*args)
|
||||
return super() if defined?(YAML::ENGINE) && !YAML::ENGINE.syck?
|
||||
|
||||
to_str.to_yaml(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -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 @@ def setup
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user