diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-28 01:23:20 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-28 01:23:20 +0000 |
commit | 3c695356ae261c0f49a52094804498b51435dfe3 (patch) | |
tree | dc68d320b0c178b8d7df39d1e8cbc33fcd5ce498 /actionpack/test/controller | |
parent | 5f4d121798b5045503e9201ae11ead82f3087c25 (diff) | |
download | rails-3c695356ae261c0f49a52094804498b51435dfe3.tar.gz rails-3c695356ae261c0f49a52094804498b51435dfe3.tar.bz2 rails-3c695356ae261c0f49a52094804498b51435dfe3.zip |
Fixed the layout defaults (closes #9564) [lifo]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7661 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/mime_responds_test.rb | 74 |
1 files changed, 71 insertions, 3 deletions
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 '<html><div id="html_missing">Hello future from Firefox!</div></html>', @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 '<html><div id="html">Hello Firefox</div></html>', @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 '<html><div id="super_iphone">Super iPhone</div></html>', @response.body + end +end +
\ No newline at end of file |