From a307b8c7dcc290705fbc06136622c004ea17976a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 9 Oct 2006 01:26:35 +0000 Subject: render_text may optionally append to the response body. render_javascript appends by default. This allows you to chain multiple render :update calls by setting @performed_render = false between them (awaiting a better public API). git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5253 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_controller/base.rb | 15 +++++++++++---- actionpack/test/controller/render_test.rb | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index d415fd086a..33c7b31bad 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* render_text may optionally append to the response body. render_javascript appends by default. This allows you to chain multiple render :update calls by setting @performed_render = false between them (awaiting a better public API). [Jeremy Kemper] + * Rename test assertion to prevent shadowing. Closes #6306. [psross] * Fixed that NumberHelper#number_to_delimiter should respect precision of higher than two digits #6231 [phallstrom] diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index acf53de2e6..f477c9d587 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -793,15 +793,22 @@ module ActionController #:nodoc: render_text(@template.render_template(type, template, nil, local_assigns), status) end - def render_text(text = nil, status = nil) #:nodoc: + def render_text(text = nil, status = nil, append_response = false) #:nodoc: @performed_render = true + response.headers['Status'] = interpret_status(status || DEFAULT_RENDER_STATUS_CODE) - response.body = text + + if append_response + response.body ||= '' + response.body << text + else + response.body = text + end end - def render_javascript(javascript, status = nil) #:nodoc: + def render_javascript(javascript, status = nil, append_response = true) #:nodoc: response.content_type = Mime::JS - render_text(javascript, status) + render_text(javascript, status, append_response) end def render_xml(xml, status = nil) #:nodoc: diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 6e37a7f142..66429662e6 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -43,6 +43,15 @@ class TestController < ActionController::Base render_text "hello world", "404 Moved" end + def render_text_appendix + render_text "hello world" + render_text ", goodbye!", "404 Not Found", true + end + + def render_nothing_with_appendix + render_text "appended", nil, true + end + def render_xml_hello @name = "David" render "test/hello" @@ -160,6 +169,18 @@ class RenderTest < Test::Unit::TestCase assert_response 404 end + def test_do_with_render_text_appendix + get :render_text_appendix + assert_response 404 + assert_equal 'hello world, goodbye!', @response.body + end + + def test_do_with_render_nothing_with_appendix + get :render_nothing_with_appendix + assert_response 200 + assert_equal 'appended', @response.body + end + def test_attempt_to_access_object_method assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone } end -- cgit v1.2.3