Skip to content
This repository
Browse code

Add tests for content_for() for read, closes #475.

  • Loading branch information...
commit 86a0f7f73594e5ba56b78b74c16cd6efa7e6cfa9 1 parent 3f36441
José Valim josevalim authored
8 actionpack/lib/action_view/helpers/capture_helper.rb
@@ -135,8 +135,12 @@ def capture(*args)
135 135 # for elements that will be fragment cached.
136 136 def content_for(name, content = nil, &block)
137 137 content = capture(&block) if block_given?
138   - result = @view_flow.append(name, content) if content
139   - result unless content
  138 + if content
  139 + @view_flow.append(name, content)
  140 + nil
  141 + else
  142 + @view_flow.get(name)
  143 + end
140 144 end
141 145
142 146 # The same as +content_for+ but when used with streaming flushes
16 actionpack/test/template/capture_helper_test.rb
@@ -38,7 +38,15 @@ def test_capture_doesnt_escape_twice
38 38 assert_equal '<em>bar</em>', string
39 39 end
40 40
41   - def test_content_for
  41 + def test_capture_used_for_read
  42 + content_for :foo, "foo"
  43 + assert_equal "foo", content_for(:foo)
  44 +
  45 + content_for(:bar){ "bar" }
  46 + assert_equal "bar", content_for(:bar)
  47 + end
  48 +
  49 + def test_content_for_question_mark
42 50 assert ! content_for?(:title)
43 51 content_for :title, 'title'
44 52 assert content_for?(:title)
@@ -49,14 +57,14 @@ def test_provide
49 57 assert !content_for?(:title)
50 58 provide :title, "hi"
51 59 assert content_for?(:title)
52   - assert_equal "hi", @view_flow.get(:title)
  60 + assert_equal "hi", content_for(:title)
53 61 provide :title, "<p>title</p>"
54   - assert_equal "hi&lt;p&gt;title&lt;/p&gt;", @view_flow.get(:title)
  62 + assert_equal "hi&lt;p&gt;title&lt;/p&gt;", content_for(:title)
55 63
56 64 @view_flow = ActionView::OutputFlow.new
57 65 provide :title, "hi"
58 66 provide :title, "<p>title</p>".html_safe
59   - assert_equal "hi<p>title</p>", @view_flow.get(:title)
  67 + assert_equal "hi<p>title</p>", content_for(:title)
60 68 end
61 69
62 70 def test_with_output_buffer_swaps_the_output_buffer_given_no_argument

0 comments on commit 86a0f7f

Please sign in to comment.
Something went wrong with that request. Please try again.