Skip to content

Commit

Permalink
Move tests for deprecated String#html_safe! to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed May 24, 2010
1 parent 3ff921a commit 60e82a3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 108 deletions.
Expand Up @@ -109,9 +109,4 @@ def html_safe
def html_safe?
false
end

def html_safe!
ActiveSupport::Deprecation.warn("Use html_safe with your strings instead of html_safe! See http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/ for the full story.", caller)
self
end
end
105 changes: 2 additions & 103 deletions activesupport/test/core_ext/string_ext_test.rb
Expand Up @@ -298,24 +298,15 @@ def to_s
assert !@string.html_safe?
end

test "A string can be marked safe using html_safe!" do
assert_deprecated do
@string.html_safe!
assert @string.html_safe?
end
test "Marking a string html_safe! doesn't work unless rails_xss is installed" do
assert_raise(NoMethodError) { @string.html_safe! }
end

test "A string can be marked safe" do
string = @string.html_safe
assert string.html_safe?
end

test "Marking a string safe returns the string using html_safe!" do
assert_deprecated do
assert_equal @string, @string.html_safe!
end
end

test "Marking a string safe returns the string" do
assert_equal @string, @string.html_safe
end
Expand All @@ -336,17 +327,6 @@ def to_s
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!
@string.html_safe!
@combination = @other_string + @string

assert_equal "otherhello", @combination
assert @combination.html_safe?
end
end

test "Adding a safe string to another safe string returns a safe string" do
@other_string = "other".html_safe
string = @string.html_safe
Expand All @@ -356,20 +336,6 @@ def to_s
assert @combination.html_safe?
end

test "Adding an unsafe string to a safe string returns an unsafe string using html_safe!" do
assert_deprecated do
@other_string = "other".html_safe!
@combination = @other_string + "<foo>"
@other_combination = @string + "<foo>"

assert_equal "other<foo>", @combination
assert_equal "hello<foo>", @other_combination

assert !@combination.html_safe?
assert !@other_combination.html_safe?
end
end

test "Adding an unsafe string to a safe string escapes it and returns a safe string" do
@other_string = "other".html_safe
@combination = @other_string + "<foo>"
Expand All @@ -382,16 +348,6 @@ def to_s
assert !@other_combination.html_safe?
end

test "Concatting safe onto unsafe yields unsafe using html_safe!" do
assert_deprecated do
@other_string = "other"
@string.html_safe!

@other_string.concat(@string)
assert !@other_string.html_safe?
end
end

test "Concatting safe onto unsafe yields unsafe" do
@other_string = "other"
string = @string.html_safe
Expand All @@ -400,32 +356,13 @@ def to_s
assert !@other_string.html_safe?
end

test "Concatting unsafe onto safe yields unsafe using html_safe!" do
assert_deprecated do
@other_string = "other".html_safe!
string = @other_string.concat("<foo>")
assert_equal "other<foo>", string
assert !string.html_safe?
end
end

test "Concatting unsafe onto safe yields escaped safe" do
@other_string = "other".html_safe
string = @other_string.concat("<foo>")
assert_equal "other&lt;foo&gt;", string
assert string.html_safe?
end

test "Concatting safe onto safe yields safe using html_safe!" do
assert_deprecated do
@other_string = "other".html_safe!
@string.html_safe!

@other_string.concat(@string)
assert @other_string.html_safe?
end
end

test "Concatting safe onto safe yields safe" do
@other_string = "other".html_safe
string = @string.html_safe
Expand All @@ -434,16 +371,6 @@ def to_s
assert @other_string.html_safe?
end

test "Concatting safe onto unsafe with << yields unsafe using html_safe!" do
assert_deprecated do
@other_string = "other"
@string.html_safe!

@other_string << @string
assert !@other_string.html_safe?
end
end

test "Concatting safe onto unsafe with << yields unsafe" do
@other_string = "other"
string = @string.html_safe
Expand All @@ -452,32 +379,13 @@ def to_s
assert !@other_string.html_safe?
end

test "Concatting unsafe onto safe with << yields unsafe using html_safe!" do
assert_deprecated do
@other_string = "other".html_safe!
string = @other_string << "<foo>"
assert_equal "other<foo>", string
assert !string.html_safe?
end
end

test "Concatting unsafe onto safe with << yields escaped safe" do
@other_string = "other".html_safe
string = @other_string << "<foo>"
assert_equal "other&lt;foo&gt;", string
assert string.html_safe?
end

test "Concatting safe onto safe with << yields safe using html_safe!" do
assert_deprecated do
@other_string = "other".html_safe!
@string.html_safe!

@other_string << @string
assert @other_string.html_safe?
end
end

test "Concatting safe onto safe with << yields safe" do
@other_string = "other".html_safe
@string.html_safe
Expand All @@ -486,15 +394,6 @@ def to_s
assert @other_string.html_safe?
end

test "Concatting a fixnum to safe always yields safe using html_safe!" do
assert_deprecated do
@string.html_safe!
@string.concat(13)
assert_equal "hello".concat(13), @string
assert @string.html_safe?
end
end

test "Concatting a fixnum to safe always yields safe" do
string = @string.html_safe
string = string.concat(13)
Expand Down

0 comments on commit 60e82a3

Please sign in to comment.