Permalink
Browse files

Fixed html_safe test cases which weren't testing correctly backport f…

…rom 3.0

[#3869 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
Santiago Pastorino and José Ignacio Costa authored and jeremy committed Feb 5, 2010
1 parent 8a0e8f0 commit 564ace6a01ac85bf8b69515f3acfba569eee6293
Showing with 27 additions and 6 deletions.
  1. +27 −6 activesupport/test/core_ext/string_ext_test.rb
@@ -285,6 +285,11 @@ def test_bytesize
class OutputSafetyTest < ActiveSupport::TestCase
def setup
@string = "hello"
+ @object = Class.new(Object) do
+ def to_s
+ "other"
+ end
+ end.new
end
test "A string is unsafe by default" do
@@ -313,6 +318,22 @@ def setup
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
+ assert !@object.html_safe?
+ end
+
+ test "Adding an object to a safe string returns a safe string" do
+ string = @string.html_safe
+ string << @object
+
+ assert_equal "helloother", string
+ assert string.html_safe?
+ end
+
test "Adding a safe string to another safe string returns a safe string using html_safe!" do
assert_deprecated do
@other_string = "other".html_safe!
@@ -371,9 +392,9 @@ def setup
test "Concatting safe onto unsafe yields unsafe" do
@other_string = "other"
- @string.html_safe
+ string = @string.html_safe
- @other_string.concat(@string)
+ @other_string.concat(string)
assert !@other_string.html_safe?
end
@@ -405,9 +426,9 @@ def setup
test "Concatting safe onto safe yields safe" do
@other_string = "other".html_safe
- @string.html_safe
+ string = @string.html_safe
- @other_string.concat(@string)
+ @other_string.concat(string)
assert @other_string.html_safe?
end
@@ -423,9 +444,9 @@ def setup
test "Concatting safe onto unsafe with << yields unsafe" do
@other_string = "other"
- @string.html_safe
+ string = @string.html_safe
- @other_string << @string
+ @other_string << string
assert !@other_string.html_safe?
end

0 comments on commit 564ace6

Please sign in to comment.