diff --git a/actionpack/lib/action_view/renderable.rb b/actionpack/lib/action_view/renderable.rb index c23b8cde892fa..5ff5569db6fcb 100644 --- a/actionpack/lib/action_view/renderable.rb +++ b/actionpack/lib/action_view/renderable.rb @@ -29,7 +29,9 @@ def render(view, local_assigns = {}) stack.push(self) # This is only used for TestResponse to set rendered_template - view.instance_variable_set(:@_first_render, self) unless view.instance_variable_get(:@_first_render) + unless is_a?(InlineTemplate) || view.instance_variable_get(:@_first_render) + view.instance_variable_set(:@_first_render, self) + end view.send(:_evaluate_assigns_and_ivars) view.send(:_set_controller_content_type, mime_type) if respond_to?(:mime_type) diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index df9376727fa43..5d97e90550297 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -39,7 +39,7 @@ def conditional_hello_with_bangs render :action => 'hello_world' end before_filter :handle_last_modified_and_etags, :only=>:conditional_hello_with_bangs - + def handle_last_modified_and_etags fresh_when(:last_modified => Time.now.utc.beginning_of_day, :etag => [ :foo, 123 ]) end @@ -337,6 +337,11 @@ def render_to_string_and_render 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" def @template.name() nil end @@ -908,6 +913,11 @@ def test_render_to_string_resets_assigns 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 get :hello_world @@ -1368,7 +1378,7 @@ def test_render_against_etag_request_should_200_when_no_match assert_equal "200 OK", @response.status assert !@response.body.empty? end - + def test_render_should_not_set_etag_when_last_modified_has_been_specified get :render_hello_world_with_last_modified_set assert_equal "200 OK", @response.status @@ -1382,7 +1392,7 @@ def test_render_with_etag expected_etag = etag_for('hello david') assert_equal expected_etag, @response.headers['ETag'] @response = ActionController::TestResponse.new - + @request.if_none_match = expected_etag get :render_hello_world_from_variable assert_equal "304 Not Modified", @response.status @@ -1407,24 +1417,24 @@ def test_etag_should_govern_renders_with_layouts_too assert_equal "\n\n

Hello

\n

This is grand!

\n\n
\n", @response.body assert_equal etag_for("\n\n

Hello

\n

This is grand!

\n\n
\n"), @response.headers['ETag'] end - + def test_etag_with_bang_should_set_etag get :conditional_hello_with_bangs assert_equal @expected_bang_etag, @response.headers["ETag"] assert_response :success end - + def test_etag_with_bang_should_obey_if_none_match @request.if_none_match = @expected_bang_etag get :conditional_hello_with_bangs assert_response :not_modified end - + protected def etag_for(text) %("#{Digest::MD5.hexdigest(text)}") end - + def expand_key(args) ActiveSupport::Cache.expand_cache_key(args) end @@ -1467,13 +1477,13 @@ def test_request_modified assert !@response.body.blank? assert_equal @last_modified, @response.headers['Last-Modified'] end - + def test_request_with_bang_gets_last_modified get :conditional_hello_with_bangs assert_equal @last_modified, @response.headers['Last-Modified'] assert_response :success end - + def test_request_with_bang_obeys_last_modified @request.if_modified_since = @last_modified get :conditional_hello_with_bangs