From 8a130edb0f7b3aacf74d080d3da3b2d871f650d6 Mon Sep 17 00:00:00 2001 From: grentis Date: Thu, 29 Dec 2011 21:58:55 +0100 Subject: content_for with flush parameter --- actionpack/test/template/capture_helper_test.rb | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/capture_helper_test.rb b/actionpack/test/template/capture_helper_test.rb index a37e3a8d6a..17469f8c3e 100644 --- a/actionpack/test/template/capture_helper_test.rb +++ b/actionpack/test/template/capture_helper_test.rb @@ -53,6 +53,13 @@ class CaptureHelperTest < ActionView::TestCase assert_equal 'foobar', content_for(:title) end + def test_content_for_with_multiple_calls_and_flush + assert ! content_for?(:title) + content_for :title, 'foo' + content_for :title, 'bar', true + assert_equal 'bar', content_for(:title) + end + def test_content_for_with_block assert ! content_for?(:title) content_for :title do @@ -63,6 +70,39 @@ class CaptureHelperTest < ActionView::TestCase assert_equal 'foobar', content_for(:title) end + def test_content_for_with_block_and_multiple_calls_with_flush + assert ! content_for?(:title) + content_for :title do + 'foo' + end + content_for :title, true do + 'bar' + end + assert_equal 'bar', content_for(:title) + end + + def test_content_for_with_block_and_multiple_calls_with_flush_nil_content + assert ! content_for?(:title) + content_for :title do + 'foo' + end + content_for :title, nil, true do + 'bar' + end + assert_equal 'bar', content_for(:title) + end + + def test_content_for_with_block_and_multiple_calls_without_flush + assert ! content_for?(:title) + content_for :title do + 'foo' + end + content_for :title, false do + 'bar' + end + assert_equal 'foobar', content_for(:title) + end + def test_content_for_with_whitespace_block assert ! content_for?(:title) content_for :title, 'foo' @@ -74,12 +114,27 @@ class CaptureHelperTest < ActionView::TestCase assert_equal 'foobar', content_for(:title) end + def test_content_for_with_whitespace_block_and_flush + assert ! content_for?(:title) + content_for :title, 'foo' + content_for :title, true do + output_buffer << " \n " + nil + end + content_for :title, 'bar', true + assert_equal 'bar', content_for(:title) + end + def test_content_for_returns_nil_when_writing assert ! content_for?(:title) assert_equal nil, content_for(:title, 'foo') assert_equal nil, content_for(:title) { output_buffer << 'bar'; nil } assert_equal nil, content_for(:title) { output_buffer << " \n "; nil } assert_equal 'foobar', content_for(:title) + assert_equal nil, content_for(:title, 'foo', true) + assert_equal nil, content_for(:title, true) { output_buffer << 'bar'; nil } + assert_equal nil, content_for(:title, true) { output_buffer << " \n "; nil } + assert_equal 'bar', content_for(:title) end def test_content_for_question_mark -- cgit v1.2.3