From cbec7e68bcea7ca366f8882675b438d8a7b1df9f Mon Sep 17 00:00:00 2001 From: Tom Ward Date: Fri, 18 Jul 2008 20:20:47 +0100 Subject: [PATCH] Set the response content type to that of found template if not explicitly set elsewhere (see ticket #444). A request to /posts.atom rendered with template 'posts.atom.builder' will now have a response type of 'application/atom+xml', instead of 'application/xml' --- actionpack/lib/action_view/base.rb | 1 + actionpack/test/controller/render_test.rb | 5 +++++ .../test/implicit_content_type.atom.builder | 2 ++ 3 files changed, 8 insertions(+), 0 deletions(-) create mode 100644 actionpack/test/fixtures/test/implicit_content_type.atom.builder diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index a6872b1..7d5b77c 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -352,6 +352,7 @@ module ActionView #:nodoc: end template = pick_template(template_path) + controller.respond_to?(:response) && controller.response.content_type ||= (template.format && Mime::Type.lookup_by_extension(template.format)) template.render_template(self, local_assigns) end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 041c54c..edb6fcd 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -467,6 +467,11 @@ class RenderTest < Test::Unit::TestCase get :render_xml_with_custom_content_type assert_equal "application/atomsvc+xml", @response.content_type end + + def test_should_use_implicit_content_type + get :implicit_content_type, :format => 'atom' + assert_equal Mime::ATOM, @response.content_type + end end class EtagRenderTest < Test::Unit::TestCase diff --git a/actionpack/test/fixtures/test/implicit_content_type.atom.builder b/actionpack/test/fixtures/test/implicit_content_type.atom.builder new file mode 100644 index 0000000..9c55bd0 --- /dev/null +++ b/actionpack/test/fixtures/test/implicit_content_type.atom.builder @@ -0,0 +1,2 @@ +xml.atom do +end \ No newline at end of file -- 1.5.3.7