From ef9566d1886af250e080870ae4e8b96b0ae46b47 Mon Sep 17 00:00:00 2001 From: Roman Le Negrate Date: Wed, 27 Aug 2008 00:23:27 +0200 Subject: [PATCH] add failing test checking that layout MIME type should match response's --- actionpack/test/controller/mime_responds_test.rb | 26 ++++++++++++++++++++ .../layouts/multi_mime_layout_post.html.erb | 1 + .../layouts/multi_mime_layout_post.js.erb | 1 + .../layouts/multi_mime_layout_post.xml.erb | 1 + .../multi_mime_layout_post/_sub_html.html.erb | 1 + .../multi_mime_layout_post/index.html.erb | 1 + .../post_test/multi_mime_layout_post/index.js.erb | 1 + .../post_test/multi_mime_layout_post/index.xml.erb | 1 + 8 files changed, 33 insertions(+), 0 deletions(-) create mode 100644 actionpack/test/fixtures/post_test/layouts/multi_mime_layout_post.html.erb create mode 100644 actionpack/test/fixtures/post_test/layouts/multi_mime_layout_post.js.erb create mode 100644 actionpack/test/fixtures/post_test/layouts/multi_mime_layout_post.xml.erb create mode 100644 actionpack/test/fixtures/post_test/multi_mime_layout_post/_sub_html.html.erb create mode 100644 actionpack/test/fixtures/post_test/multi_mime_layout_post/index.html.erb create mode 100644 actionpack/test/fixtures/post_test/multi_mime_layout_post/index.js.erb create mode 100644 actionpack/test/fixtures/post_test/multi_mime_layout_post/index.xml.erb diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 0d508eb..410aab6 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -509,6 +509,16 @@ class SuperPostController < PostController end end +class MultiMimeLayoutPostController < AbstractPostController + def index + respond_to do |type| + type.html + type.xml + type.js + end + end +end + class MimeControllerLayoutsTest < Test::Unit::TestCase def setup @request = ActionController::TestRequest.new @@ -537,4 +547,20 @@ class MimeControllerLayoutsTest < Test::Unit::TestCase get :index assert_equal '
Super iPhone
', @response.body end + + def test_layout_mime_should_match_responses + @controller = MultiMimeLayoutPostController.new + + @request.accept = "text/html" + get :index + assert_equal 'layout.html.erb > index.html.erb', @response.body + + @request.accept = "text/xml" + get :index + assert_equal 'layout.xml.erb > index.xml.erb', @response.body + + @request.accept = "application/x-javascript" + get :index + assert_equal 'layout.js.erb > index.js.erb (_sub_html.html.erb)', @response.body + end end diff --git a/actionpack/test/fixtures/post_test/layouts/multi_mime_layout_post.html.erb b/actionpack/test/fixtures/post_test/layouts/multi_mime_layout_post.html.erb new file mode 100644 index 0000000..932f5cf --- /dev/null +++ b/actionpack/test/fixtures/post_test/layouts/multi_mime_layout_post.html.erb @@ -0,0 +1 @@ +layout.html.erb > <%= yield %> \ No newline at end of file diff --git a/actionpack/test/fixtures/post_test/layouts/multi_mime_layout_post.js.erb b/actionpack/test/fixtures/post_test/layouts/multi_mime_layout_post.js.erb new file mode 100644 index 0000000..bc4995b --- /dev/null +++ b/actionpack/test/fixtures/post_test/layouts/multi_mime_layout_post.js.erb @@ -0,0 +1 @@ +layout.js.erb > <%= yield %> \ No newline at end of file diff --git a/actionpack/test/fixtures/post_test/layouts/multi_mime_layout_post.xml.erb b/actionpack/test/fixtures/post_test/layouts/multi_mime_layout_post.xml.erb new file mode 100644 index 0000000..91ee66d --- /dev/null +++ b/actionpack/test/fixtures/post_test/layouts/multi_mime_layout_post.xml.erb @@ -0,0 +1 @@ +layout.xml.erb > <%= yield %> \ No newline at end of file diff --git a/actionpack/test/fixtures/post_test/multi_mime_layout_post/_sub_html.html.erb b/actionpack/test/fixtures/post_test/multi_mime_layout_post/_sub_html.html.erb new file mode 100644 index 0000000..c25c99a --- /dev/null +++ b/actionpack/test/fixtures/post_test/multi_mime_layout_post/_sub_html.html.erb @@ -0,0 +1 @@ +_sub_html.html.erb \ No newline at end of file diff --git a/actionpack/test/fixtures/post_test/multi_mime_layout_post/index.html.erb b/actionpack/test/fixtures/post_test/multi_mime_layout_post/index.html.erb new file mode 100644 index 0000000..81a0589 --- /dev/null +++ b/actionpack/test/fixtures/post_test/multi_mime_layout_post/index.html.erb @@ -0,0 +1 @@ +index.html.erb \ No newline at end of file diff --git a/actionpack/test/fixtures/post_test/multi_mime_layout_post/index.js.erb b/actionpack/test/fixtures/post_test/multi_mime_layout_post/index.js.erb new file mode 100644 index 0000000..32548cb --- /dev/null +++ b/actionpack/test/fixtures/post_test/multi_mime_layout_post/index.js.erb @@ -0,0 +1 @@ +index.js.erb (<%= render :partial => 'sub_html'%>) \ No newline at end of file diff --git a/actionpack/test/fixtures/post_test/multi_mime_layout_post/index.xml.erb b/actionpack/test/fixtures/post_test/multi_mime_layout_post/index.xml.erb new file mode 100644 index 0000000..45674a2 --- /dev/null +++ b/actionpack/test/fixtures/post_test/multi_mime_layout_post/index.xml.erb @@ -0,0 +1 @@ +index.xml.erb \ No newline at end of file -- 1.5.5.3 From fbc2ffd8af236176b6c0ce819b4b9f064c86486a Mon Sep 17 00:00:00 2001 From: Roman Le Negrate Date: Wed, 27 Aug 2008 02:47:07 +0200 Subject: [PATCH] attempt at fixing previous failing test: fixed when running mime_responds_test alone, but another assertion fails for no apparent reason when running the full actionpack test suite --- actionpack/lib/action_view/base.rb | 1 - actionpack/test/controller/mime_responds_test.rb | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index c65048b..882632b 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -323,7 +323,6 @@ module ActionView #:nodoc: elsif _first_render && template = self.view_paths["#{template_file_name}.#{_first_render.format_and_extension}"] template elsif template_format == :js && template = self.view_paths["#{template_file_name}.html"] - @template_format = :html template else template = Template.new(template_path, view_paths) diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 410aab6..0f1cbf8 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -477,6 +477,11 @@ end class AbstractPostController < ActionController::Base self.view_paths = File.dirname(__FILE__) + "/../fixtures/post_test/" + + protected + def rescue_action(e) + raise + end end # For testing layouts which are set automatically @@ -548,7 +553,7 @@ class MimeControllerLayoutsTest < Test::Unit::TestCase assert_equal '
Super iPhone
', @response.body end - def test_layout_mime_should_match_responses + def test_layout_mime_should_match_that_of_response @controller = MultiMimeLayoutPostController.new @request.accept = "text/html" -- 1.5.5.3