From a4ba384720501fc9a029bd673ce3567b158cc654 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Sun, 23 Aug 2009 19:43:46 -0400 Subject: [PATCH] Adding test for content_for used to populate template page title and layout title. --- actionpack/lib/action_view/template/template.rb | 1 + actionpack/test/controller/capture_test.rb | 13 +++++++++++++ .../test/content_for_template_and_layout.erb | 2 ++ 3 files changed, 16 insertions(+), 0 deletions(-) create mode 100644 actionpack/test/fixtures/test/content_for_template_and_layout.erb diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb index 7d6964e..a0d80d0 100644 --- a/actionpack/lib/action_view/template/template.rb +++ b/actionpack/lib/action_view/template/template.rb @@ -28,6 +28,7 @@ module ActionView def render(view, locals, &block) method_name = compile(locals, view) + block ||= proc {|*names| view._layout_for(names) } view.send(method_name, locals, &block) rescue Exception => e if e.is_a?(TemplateError) diff --git a/actionpack/test/controller/capture_test.rb b/actionpack/test/controller/capture_test.rb index 06a5af6..2e27feb 100644 --- a/actionpack/test/controller/capture_test.rb +++ b/actionpack/test/controller/capture_test.rb @@ -20,6 +20,10 @@ class CaptureController < ActionController::Base def non_erb_block_content_for render :layout => "talk_from_action" end + + def content_for_template_and_layout + render :layout => "talk_from_action" + end def rescue_action(e) raise end end @@ -60,9 +64,18 @@ class CaptureTest < ActionController::TestCase get :non_erb_block_content_for assert_equal expected_content_for_output, @response.body end + + def test_content_for_template_and_layout + get :content_for_template_and_layout + assert_equal expected_content_for_template_and_layout_output, @response.body + end private def expected_content_for_output "Putting stuff in the title!\n\nGreat stuff!" end + + def expected_content_for_template_and_layout_output + "Custom Page Title\n\n

Custom Page Title

" + end end diff --git a/actionpack/test/fixtures/test/content_for_template_and_layout.erb b/actionpack/test/fixtures/test/content_for_template_and_layout.erb new file mode 100644 index 0000000..2cb2014 --- /dev/null +++ b/actionpack/test/fixtures/test/content_for_template_and_layout.erb @@ -0,0 +1,2 @@ +<% content_for(:title,'Custom Page Title') %> +

<%= yield(:title) %>

\ No newline at end of file -- 1.6.3.1