From 3c695356ae261c0f49a52094804498b51435dfe3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 28 Sep 2007 01:23:20 +0000 Subject: Fixed the layout defaults (closes #9564) [lifo] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7661 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/mime_responds_test.rb | 74 +++++++++++++++++++++++- 1 file changed, 71 insertions(+), 3 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 0dc063a451..e0c0d1613a 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -429,8 +429,76 @@ class MimeControllerTest < Test::Unit::TestCase assert_equal '
Hello future from Firefox!
', @response.body @request.env["HTTP_ACCEPT"] = "text/iphone" - get :iphone_with_html_response_type_without_layout - assert_equal 'Hello iPhone future from iPhone!', @response.body - assert_equal "text/html", @response.content_type + assert_raises(ActionController::MissingTemplate) { get :iphone_with_html_response_type_without_layout } end end + +class AbstractPostController < ActionController::Base + class << self + def view_paths + [ File.dirname(__FILE__) + "/../fixtures/post_test/" ] + end + end +end + +# For testing layouts which are set automatically +class PostController < AbstractPostController + around_filter :with_iphone + + def index + respond_to do |type| + type.html + type.iphone + end + end + + protected + + def with_iphone + Mime::Type.register_alias("text/html", :iphone) + request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone" + yield + Mime.send :remove_const, :IPHONE + end + +end + +class SuperPostController < PostController + def index + respond_to do |type| + type.html + type.iphone + end + end +end + +class MimeControllerLayoutsTest < Test::Unit::TestCase + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @controller = PostController.new + @request.host = "www.example.com" + end + + def test_missing_layout_renders_properly + get :index + assert_equal '
Hello Firefox
', @response.body + + @request.env["HTTP_ACCEPT"] = "text/iphone" + get :index + assert_equal 'Hello iPhone', @response.body + end + + def test_format_with_inherited_layouts + @controller = SuperPostController.new + + get :index + assert_equal 'Super Firefox', @response.body + + @request.env["HTTP_ACCEPT"] = "text/iphone" + get :index + assert_equal '
Super iPhone
', @response.body + end +end + \ No newline at end of file -- cgit v1.2.3