mirror of
https://github.com/github/rails.git
synced 2026-01-30 08:48:06 -05:00
Added that render :xml will try to call to_xml if it can [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6574 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
*SVN*
|
||||
|
||||
* Added that render :xml will try to call to_xml if it can [DHH]. Makes these work:
|
||||
|
||||
render :xml => post
|
||||
render :xml => comments
|
||||
|
||||
* Added :location option to render so that the common pattern of rendering a response after creating a new resource is now a 1-liner [DHH]
|
||||
|
||||
render :xml => post.to_xml, :status => :created, :location => post_url(post)
|
||||
|
||||
@@ -879,7 +879,7 @@ module ActionController #:nodoc:
|
||||
|
||||
def render_xml(xml, status = nil) #:nodoc:
|
||||
response.content_type = Mime::XML
|
||||
render_text(xml, status)
|
||||
render_text(xml.respond_to?(:to_xml) ? xml.to_xml : xml, status)
|
||||
end
|
||||
|
||||
def render_json(json, callback = nil, status = nil) #:nodoc:
|
||||
|
||||
@@ -258,6 +258,20 @@ class NewRenderTestController < ActionController::Base
|
||||
head :forbidden, :x_custom_header => "something"
|
||||
end
|
||||
|
||||
def render_with_location
|
||||
render :xml => "<hello/>", :location => "http://example.com", :status => 201
|
||||
end
|
||||
|
||||
def render_with_to_xml
|
||||
to_xmlable = Class.new do
|
||||
def to_xml
|
||||
"<i-am-xml/>"
|
||||
end
|
||||
end.new
|
||||
|
||||
render :xml => to_xmlable
|
||||
end
|
||||
|
||||
helper NewRenderTestHelper
|
||||
helper do
|
||||
def rjs_helper_method(value)
|
||||
@@ -742,4 +756,14 @@ EOS
|
||||
assert_equal "something", @response.headers["X-Custom-Header"]
|
||||
assert_response :forbidden
|
||||
end
|
||||
end
|
||||
|
||||
def test_rendering_with_location_should_set_header
|
||||
get :render_with_location
|
||||
assert_equal "http://example.com", @response.headers["Location"]
|
||||
end
|
||||
|
||||
def test_rendering_xml_should_call_to_xml_if_possible
|
||||
get :render_with_to_xml
|
||||
assert_equal "<i-am-xml/>", @response.body
|
||||
end
|
||||
end
|
||||
@@ -73,10 +73,6 @@ class TestController < ActionController::Base
|
||||
head :ok
|
||||
end
|
||||
|
||||
def location
|
||||
render :xml => "<hello/>", :location => "http://example.com", :status => 201
|
||||
end
|
||||
|
||||
def greeting
|
||||
# let's just rely on the template
|
||||
end
|
||||
@@ -372,11 +368,6 @@ class RenderTest < Test::Unit::TestCase
|
||||
assert_equal '<test>passed formatted html erb</test>', @response.body
|
||||
end
|
||||
|
||||
def test_rendering_with_location_should_set_header
|
||||
get :location
|
||||
assert_equal "http://example.com", @response.headers["Location"]
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
def assert_deprecated_render(&block)
|
||||
|
||||
Reference in New Issue
Block a user