mirror of
https://github.com/github/rails.git
synced 2026-01-29 00:08:15 -05:00
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
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user