Permalink
Browse files

Ensure that calling content_tag_for in a helper doesn't cause duplica…

…te output.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#871 state:committed]
  • Loading branch information...
1 parent d0b949d commit db26b47b9f4dbebd478a5fe6c0dcd38b8697939a @tomlea tomlea committed with NZKoz Aug 26, 2008
@@ -49,9 +49,9 @@ def div_for(record, *args, &block)
#
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 @@ def test_content_tag_for_with_extra_html_tags
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>)

0 comments on commit db26b47

Please sign in to comment.