Skip to content

Commit

Permalink
Added failing tests for iphone
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7629 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Sep 25, 2007
1 parent 3b98b68 commit 55a9c86
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
15 changes: 11 additions & 4 deletions actionpack/lib/action_controller/layout.rb
Expand Up @@ -234,10 +234,9 @@ def active_layout(passed_layout = nil)


protected protected
def render_with_a_layout(options = nil, &block) #:nodoc: def render_with_a_layout(options = nil, &block) #:nodoc:
if template_with_options = options.is_a?(Hash) template_with_options = options.is_a?(Hash)
response.template.template_format = options[:content_type].to_sym if options[:content_type] set_template_format(options)
end

if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options)) if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options))
assert_existence_of_template_file(layout) assert_existence_of_template_file(layout)


Expand Down Expand Up @@ -307,5 +306,13 @@ def layout_directory?(layout_name)
self.class.send(:layout_directory_exists_cache)[File.dirname(template_path)] self.class.send(:layout_directory_exists_cache)[File.dirname(template_path)]
end end
end end

def set_template_format(options)
if options.is_a?(Hash) && options[:content_type]
response.template.template_format = options[:content_type].to_sym
elsif params[:format]
response.template.template_format = Mime::Type.lookup(Mime::Type.lookup_by_extension(params[:format]).to_s).to_sym
end
end
end end
end end
5 changes: 3 additions & 2 deletions actionpack/test/controller/mime_responds_test.rb
Expand Up @@ -116,7 +116,8 @@ def all_types_with_layout


def iphone_with_html_response_type def iphone_with_html_response_type
Mime::Type.register_alias("text/html", :iphone) Mime::Type.register_alias("text/html", :iphone)

request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"

respond_to do |type| respond_to do |type|
type.html { @type = "Firefox" } type.html { @type = "Firefox" }
type.iphone { @type = "iPhone" } type.iphone { @type = "iPhone" }
Expand Down Expand Up @@ -399,7 +400,7 @@ def test_format_with_custom_response_type


get :iphone_with_html_response_type, :format => "iphone" get :iphone_with_html_response_type, :format => "iphone"
assert_equal "text/html", @response.content_type assert_equal "text/html", @response.content_type
assert_equal "<html>Hello future from iPhone!</html>", @response.body assert_equal "<html>Hello iPhone future from iPhone!</html>", @response.body
end end


def test_format_with_custom_response_type_and_request_headers def test_format_with_custom_response_type_and_request_headers
Expand Down
@@ -0,0 +1 @@
Hello iPhone future from <%= @type -%>!

0 comments on commit 55a9c86

Please sign in to comment.