Skip to content

Commit

Permalink
Make content_tag_for work without block
Browse files Browse the repository at this point in the history
This is version of #8640 for master
  • Loading branch information
rafaelfranca committed Jan 2, 2013
1 parent 51ab77e commit 7e2ef18
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##

* Fix a bug in `content_tag_for` that prevents it for work without a block.

*Jasl*

* Change the stylesheet of exception pages for development mode.
Additionally display also the line of code and fragment that raised
the exception in all exceptions pages.
Expand Down
6 changes: 5 additions & 1 deletion actionpack/lib/action_view/helpers/record_tag_helper.rb
Expand Up @@ -95,7 +95,11 @@ def content_tag_for_single_record(tag_name, record, prefix, options, &block)
options[:class] = "#{dom_class(record, prefix)} #{options[:class]}".rstrip
options[:id] = dom_id(record, prefix)

content_tag(tag_name, capture(record, &block), options)
if block_given?
content_tag(tag_name, capture(record, &block), options)
else
content_tag(tag_name, "", options)
end
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/template/record_tag_helper_test.rb
Expand Up @@ -75,6 +75,14 @@ def test_content_tag_for_collection
assert_dom_equal expected, actual
end

def test_content_tag_for_collection_without_given_block
post_1 = RecordTagPost.new.tap { |post| post.id = 101; post.body = "Hello!" }
post_2 = RecordTagPost.new.tap { |post| post.id = 102; post.body = "World!" }
expected = %(<li class="record_tag_post" id="record_tag_post_101"></li>\n<li class="record_tag_post" id="record_tag_post_102"></li>)
actual = content_tag_for(:li, [post_1, post_2])
assert_dom_equal expected, actual
end

def test_div_for_collection
post_1 = RecordTagPost.new { |post| post.id = 101; post.body = "Hello!" }
post_2 = RecordTagPost.new { |post| post.id = 102; post.body = "World!" }
Expand Down

0 comments on commit 7e2ef18

Please sign in to comment.