From 561885aea28c9422fbdfb2be54220b10d4911973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Dec 2009 12:32:16 +0100 Subject: String#<< should work for any object which responds to :to_str, so enable this without the performance hit and make Fixnum safe by default. --- activesupport/test/core_ext/string_ext_test.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 56ed296dac..6ed209f724 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -350,6 +350,24 @@ class OutputSafetyTest < ActiveSupport::TestCase assert_equal @string, @string.html_safe! end + test "A fixnum is safe by default" do + assert 5.html_safe? + end + + test "An object is unsafe by default" do + klass = Class.new(Object) do + def to_str + "other" + end + end + + @string.html_safe! + @string << klass.new + + assert_equal "helloother", @string + assert !@string.html_safe? + end + test "Adding a safe string to another safe string returns a safe string" do @other_string = "other".html_safe! @string.html_safe! @@ -416,4 +434,10 @@ class OutputSafetyTest < ActiveSupport::TestCase @other_string << @string assert @other_string.html_safe? end + + test "Concatting a fixnum to safe always yields safe" do + @string.html_safe! + @string.concat(13) + assert @string.html_safe? + end end -- cgit v1.2.3