public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
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]
Tom Lea (author)
Tue Aug 26 03:08:31 -0700 2008
NZKoz (committer)
Fri Aug 29 11:52:01 -0700 2008
commit  db26b47b9f4dbebd478a5fe6c0dcd38b8697939a
tree    7312c03896fef70832bb116c0f644bbb222b3c9e
parent  d0b949d87375ae351757adffd192d8cb1f3dbf8d
...
49
50
51
52
53
54
 
 
 
55
56
57
...
49
50
51
 
 
 
52
53
54
55
56
57
0
@@ -49,9 +49,9 @@ module ActionView
0
       #
0
       def content_tag_for(tag_name, record, *args, &block)
0
         prefix  = args.first.is_a?(Hash) ? nil : args.shift
0
-        options = args.first.is_a?(Hash) ? args.shift : {}
0
-        concat content_tag(tag_name, capture(&block), 
0
-          options.merge({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) }))
0
+        options = args.extract_options!
0
+        options.merge!({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) })
0
+        content_tag(tag_name, options, &block)
0
       end
0
     end
0
   end
...
34
35
36
 
 
 
 
 
 
 
 
37
38
39
...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
0
@@ -34,6 +34,14 @@ class RecordTagHelperTest < ActionView::TestCase
0
     assert_dom_equal expected, actual
0
   end
0
 
0
+  def test_block_not_in_erb_multiple_calls
0
+    expected = %(<div class="post bar" id="post_45">#{@post.body}</div>)
0
+    actual = div_for(@post, :class => "bar") { @post.body }
0
+    assert_dom_equal expected, actual
0
+    actual = div_for(@post, :class => "bar") { @post.body }
0
+    assert_dom_equal expected, actual
0
+  end
0
+
0
   def test_block_works_with_content_tag_for_in_erb
0
     __in_erb_template = ''
0
     expected = %(<tr class="post" id="post_45">#{@post.body}</tr>)

Comments