require 'abstract_unit' class OutputSafetyHelperTest < ActionView::TestCase tests ActionView::Helpers::OutputSafetyHelper def setup @string = "hello" end test "raw returns the safe string" do result = raw(@string) assert_equal @string, result assert result.html_safe? end test "raw handles nil values correctly" do assert_equal "", raw(nil) end test "safe_join should html_escape any items, including the separator, if they are not html_safe" do joined = safe_join(["

foo

".html_safe, "

bar

"], "
") assert_equal "

foo

<br /><p>bar</p>", joined joined = safe_join(["

foo

".html_safe, "

bar

".html_safe], "
".html_safe) assert_equal "

foo


bar

", joined end test "safe_join should work recursively similarly to Array.join" do joined = safe_join(['a',['b','c']], ':') assert_equal 'a:b:c', joined joined = safe_join(['"a"',['','']], '
') assert_equal '"a" <br/> <b> <br/> <c>', joined end end