Permalink
Browse files

Merge pull request #2872 from sikachu/content_tag_html_safe

Make sure that result from content_tag_for with collection is html_safe
  • Loading branch information...
2 parents f4a690d + ffe56f3 commit a23e3855c5a8a2b0747c856c195ab7adc17f601e @spastorino spastorino committed Sep 5, 2011
@@ -84,7 +84,7 @@ def content_tag_for(tag_name, single_or_multiple_records, prefix = nil, options
if single_or_multiple_records.respond_to?(:to_ary)
single_or_multiple_records.to_ary.map do |single_record|
capture { content_tag_for_single_record(tag_name, single_record, prefix, options, &block) }
- end.join("\n")
+ end.join("\n").html_safe
else
content_tag_for_single_record(tag_name, single_or_multiple_records, prefix, options, &block)
end
@@ -83,4 +83,16 @@ def test_div_for_collection
actual = div_for([post_1, post_2]) { |post| concat post.body }
assert_dom_equal expected, actual
end
+
+ def test_content_tag_for_single_record_is_html_safe
+ result = div_for(@post, :class => "bar") { concat @post.body }
+ assert result.html_safe?
+ end
+
+ def test_content_tag_for_collection_is_html_safe
+ post_1 = Post.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true }
+ post_2 = Post.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true }
+ result = content_tag_for(:li, [post_1, post_2]) { |post| concat post.body }
+ assert result.html_safe?
+ end
end

0 comments on commit a23e385

Please sign in to comment.