From 40aacf747172129147a754b2d088aa0b91f446b6 Mon Sep 17 00:00:00 2001 From: Luke Melia Date: Sat, 15 Nov 2008 23:52:51 -0500 Subject: [PATCH] Prevent assert_template failures when a render :inline is called before rendering a file-based template. --- actionpack/lib/action_controller/base.rb | 1 + actionpack/lib/action_view/base.rb | 6 ++++++ actionpack/test/controller/render_test.rb | 10 ++++++++++ 3 files changed, 17 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index f35c42f..4b180bb 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -983,6 +983,7 @@ module ActionController #:nodoc: # Clears the rendered results, allowing for another render to be performed. def erase_render_results #:nodoc: response.body = nil + response.template.reset_inline_first_render @performed_render = false end diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 945246a..dffb876 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -277,6 +277,12 @@ module ActionView #:nodoc: def template @_render_stack.last end + + def reset_inline_first_render + if instance_variable_get(:@_first_render).is_a?(InlineTemplate) + instance_variable_set(:@_first_render, nil) + end + end private # Evaluates the local assigns and controller ivars, pushes them to the view. diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index df93767..5dafacd 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -336,6 +336,11 @@ class TestController < ActionController::Base @stuff = render_to_string :text => "here is some cached stuff" render :text => "Hi web users! #{@stuff}" end + + def render_to_string_with_inline_and_render + render_to_string :inline => "<%= 'dlrow olleh'.reverse %>" + render :template => "test/hello_world" + end def rendering_with_conflicting_local_vars @name = "David" @@ -907,6 +912,11 @@ class RenderTest < Test::Unit::TestCase get :render_to_string_test assert_equal "The value of foo is: ::this is a test::\n", @response.body end + + def test_render_to_string_inline + get :render_to_string_with_inline_and_render + assert_template "test/hello_world" + end def test_nested_rendering @controller = Fun::GamesController.new -- 1.6.0.3