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

Changeset 7514

Show
Ignore:
Timestamp:
09/18/07 23:10:34 (1 year ago)
Author:
david
Message:

Fixed that default layouts did not take the format into account #9564 [lifofifo]

Files:

Legend:

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

    r7487 r7514  
    11*SVN* 
     2 
     3* Fixed that default layouts did not take the format into account #9564 [lifofifo] 
    24 
    35* Fixed optimized route segment escaping.  #9562 [wildchild, Jeremy Kemper] 
  • trunk/actionpack/lib/action_controller/layout.rb

    r7438 r7514  
    235235    protected 
    236236      def render_with_a_layout(options = nil, &block) #:nodoc: 
    237         template_with_options = options.is_a?(Hash) 
     237        if template_with_options = options.is_a?(Hash) 
     238          response.template.template_format = options[:content_type].to_sym if options[:content_type] 
     239        end 
    238240 
    239241        if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options)) 
  • trunk/actionpack/test/controller/mime_responds_test.rb

    r7479 r7514  
    113113      type.js 
    114114    end 
     115  end  
     116   
     117  def iphone_with_html_response_type  
     118    Mime::Type.register("text/iphone", :iphone) 
     119 
     120    respond_to do |type| 
     121      type.html   { @type = "Firefox" } 
     122      type.iphone { @type = "iPhone"; render :content_type => Mime::HTML } 
     123    end 
     124 
     125    Mime.send :remove_const, :IPHONE 
    115126  end 
    116127 
     
    121132  protected 
    122133    def set_layout 
    123       if action_name == "all_types_with_layout" 
     134      if ["all_types_with_layout", "iphone_with_html_response_type"].include?(action_name) 
    124135        "standard" 
    125136      end 
     
    381392    get :using_defaults, :format => "xml" 
    382393    assert_equal "using_defaults - xml", @response.body 
    383   end 
     394  end  
     395   
     396  def test_format_with_custom_response_type 
     397    get :iphone_with_html_response_type 
     398    assert_equal "<html>Hello future from Firefox!</html>", @response.body  
     399     
     400    get :iphone_with_html_response_type, :format => "iphone" 
     401    assert_equal "text/html", @response.content_type 
     402    assert_equal "<html>Hello future from iPhone!</html>", @response.body 
     403  end  
     404   
     405  def test_format_with_custom_response_type_and_request_headers 
     406    @request.env["HTTP_ACCEPT"] = "text/iphone" 
     407    get :iphone_with_html_response_type 
     408    assert_equal "<html>Hello future from iPhone!</html>", @response.body 
     409    assert_equal "text/html", @response.content_type 
     410  end  
    384411end