mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure that calling content_tag_for in a helper doesn't cause duplicate output.
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#871 state:committed]
This commit is contained in:
parent
d0b949d873
commit
db26b47b9f
2 changed files with 11 additions and 3 deletions
|
@ -49,9 +49,9 @@ module ActionView
|
|||
#
|
||||
def content_tag_for(tag_name, record, *args, &block)
|
||||
prefix = args.first.is_a?(Hash) ? nil : args.shift
|
||||
options = args.first.is_a?(Hash) ? args.shift : {}
|
||||
concat content_tag(tag_name, capture(&block),
|
||||
options.merge({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) }))
|
||||
options = args.extract_options!
|
||||
options.merge!({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) })
|
||||
content_tag(tag_name, options, &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,6 +34,14 @@ class RecordTagHelperTest < ActionView::TestCase
|
|||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_block_not_in_erb_multiple_calls
|
||||
expected = %(<div class="post bar" id="post_45">#{@post.body}</div>)
|
||||
actual = div_for(@post, :class => "bar") { @post.body }
|
||||
assert_dom_equal expected, actual
|
||||
actual = div_for(@post, :class => "bar") { @post.body }
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_block_works_with_content_tag_for_in_erb
|
||||
__in_erb_template = ''
|
||||
expected = %(<tr class="post" id="post_45">#{@post.body}</tr>)
|
||||
|
|
Loading…
Reference in a new issue