aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/mime_responds_test.rb74
-rw-r--r--actionpack/test/fixtures/post_test/layouts/post.html.erb1
-rw-r--r--actionpack/test/fixtures/post_test/layouts/super_post.iphone.erb1
-rw-r--r--actionpack/test/fixtures/post_test/post/index.html.erb1
-rw-r--r--actionpack/test/fixtures/post_test/post/index.iphone.erb1
-rw-r--r--actionpack/test/fixtures/post_test/super_post/index.html.erb1
-rw-r--r--actionpack/test/fixtures/post_test/super_post/index.iphone.erb1
7 files changed, 77 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
diff --git a/actionpack/test/fixtures/post_test/layouts/post.html.erb b/actionpack/test/fixtures/post_test/layouts/post.html.erb
new file mode 100644
index 0000000000..c6c1a586dd
--- /dev/null
+++ b/actionpack/test/fixtures/post_test/layouts/post.html.erb
@@ -0,0 +1 @@
+<html><div id="html"><%= yield %></div></html> \ No newline at end of file
diff --git a/actionpack/test/fixtures/post_test/layouts/super_post.iphone.erb b/actionpack/test/fixtures/post_test/layouts/super_post.iphone.erb
new file mode 100644
index 0000000000..db0e43694d
--- /dev/null
+++ b/actionpack/test/fixtures/post_test/layouts/super_post.iphone.erb
@@ -0,0 +1 @@
+<html><div id="super_iphone"><%= yield %></div></html> \ No newline at end of file
diff --git a/actionpack/test/fixtures/post_test/post/index.html.erb b/actionpack/test/fixtures/post_test/post/index.html.erb
new file mode 100644
index 0000000000..b349b25618
--- /dev/null
+++ b/actionpack/test/fixtures/post_test/post/index.html.erb
@@ -0,0 +1 @@
+Hello Firefox \ No newline at end of file
diff --git a/actionpack/test/fixtures/post_test/post/index.iphone.erb b/actionpack/test/fixtures/post_test/post/index.iphone.erb
new file mode 100644
index 0000000000..d741e44351
--- /dev/null
+++ b/actionpack/test/fixtures/post_test/post/index.iphone.erb
@@ -0,0 +1 @@
+Hello iPhone \ No newline at end of file
diff --git a/actionpack/test/fixtures/post_test/super_post/index.html.erb b/actionpack/test/fixtures/post_test/super_post/index.html.erb
new file mode 100644
index 0000000000..7fc2eb190a
--- /dev/null
+++ b/actionpack/test/fixtures/post_test/super_post/index.html.erb
@@ -0,0 +1 @@
+Super Firefox \ No newline at end of file
diff --git a/actionpack/test/fixtures/post_test/super_post/index.iphone.erb b/actionpack/test/fixtures/post_test/super_post/index.iphone.erb
new file mode 100644
index 0000000000..99063a8d8c
--- /dev/null
+++ b/actionpack/test/fixtures/post_test/super_post/index.iphone.erb
@@ -0,0 +1 @@
+Super iPhone \ No newline at end of file