Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6574

Show
Ignore:
Timestamp:
04/24/07 18:29:37 (3 years ago)
Author:
david
Message:

Added that render :xml will try to call to_xml if it can [DHH]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r6572 r6574  
    11*SVN* 
     2 
     3* Added that render :xml will try to call to_xml if it can [DHH]. Makes these work: 
     4 
     5    render :xml => post 
     6    render :xml => comments 
    27 
    38* 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] 
  • trunk/actionpack/lib/action_controller/base.rb

    r6572 r6574  
    880880      def render_xml(xml, status = nil) #:nodoc: 
    881881        response.content_type = Mime::XML 
    882         render_text(xml, status) 
     882        render_text(xml.respond_to?(:to_xml) ? xml.to_xml : xml, status) 
    883883      end 
    884884 
  • trunk/actionpack/test/controller/new_render_test.rb

    r6399 r6574  
    257257  def head_with_status_code_first 
    258258    head :forbidden, :x_custom_header => "something" 
     259  end 
     260 
     261  def render_with_location 
     262    render :xml => "<hello/>", :location => "http://example.com", :status => 201 
     263  end 
     264 
     265  def render_with_to_xml 
     266    to_xmlable = Class.new do 
     267      def to_xml 
     268        "<i-am-xml/>" 
     269      end 
     270    end.new 
     271     
     272    render :xml => to_xmlable 
    259273  end 
    260274 
     
    743757    assert_response :forbidden 
    744758  end 
     759 
     760  def test_rendering_with_location_should_set_header 
     761    get :render_with_location 
     762    assert_equal "http://example.com", @response.headers["Location"] 
     763  end 
     764   
     765  def test_rendering_xml_should_call_to_xml_if_possible 
     766    get :render_with_to_xml 
     767    assert_equal "<i-am-xml/>", @response.body 
     768  end 
    745769end 
  • trunk/actionpack/test/controller/render_test.rb

    r6572 r6574  
    7272  def heading 
    7373    head :ok 
    74   end 
    75  
    76   def location 
    77     render :xml => "<hello/>", :location => "http://example.com", :status => 201 
    7874  end 
    7975 
     
    373369  end 
    374370 
    375   def test_rendering_with_location_should_set_header 
    376     get :location 
    377     assert_equal "http://example.com", @response.headers["Location"] 
    378   end 
    379  
    380371 
    381372  protected