aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/string_ext_test.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-12-25 12:32:16 +0100
committerJosé Valim <jose.valim@gmail.com>2009-12-26 14:11:04 +0100
commit561885aea28c9422fbdfb2be54220b10d4911973 (patch)
tree963051968b814c6e93e87e12c7baa3a4a916717a /activesupport/test/core_ext/string_ext_test.rb
parent9a9f97af2815469e6f28dee9b88577251ef1b832 (diff)
downloadrails-561885aea28c9422fbdfb2be54220b10d4911973.tar.gz
rails-561885aea28c9422fbdfb2be54220b10d4911973.tar.bz2
rails-561885aea28c9422fbdfb2be54220b10d4911973.zip
String#<< should work for any object which responds to :to_str, so enable this without the performance hit and make Fixnum safe by default.
Diffstat (limited to 'activesupport/test/core_ext/string_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb24
1 files changed, 24 insertions, 0 deletions
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