From dfc57da8331513ff035dd05e013f98026bf0c4fe Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Thu, 5 Mar 2009 19:57:40 -0500 Subject: [PATCH] fix HTML fallback for explicit templates; restore function of test from #1844 --- actionpack/lib/action_controller/layout.rb | 10 +++++----- actionpack/test/controller/render_test.rb | 16 ++++++++++++++++ .../test/fixtures/layouts/default_html.html.erb | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 actionpack/test/fixtures/layouts/default_html.html.erb diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index ccd9605..6ec0c1b 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -198,7 +198,7 @@ module ActionController #:nodoc: # is called and the return value is used. Likewise if the layout was specified as an inline method (through a proc or method # object). If the layout was defined without a directory, layouts is assumed. So layout "weblog/standard" will return # weblog/standard, but layout "standard" will return layouts/standard. - def active_layout(passed_layout = nil) + def active_layout(passed_layout = nil, options = {}) layout = passed_layout || default_layout return layout if layout.respond_to?(:render) @@ -208,7 +208,7 @@ module ActionController #:nodoc: else layout end - find_layout(active_layout, default_template_format) if active_layout + find_layout(active_layout, default_template_format, options[:html_fallback]) if active_layout end private @@ -220,8 +220,8 @@ module ActionController #:nodoc: nil end - def find_layout(layout, format) #:nodoc: - view_paths.find_template(layout.to_s =~ /layouts\// ? layout : "layouts/#{layout}", format, false) + def find_layout(layout, format, html_fallback=false) #:nodoc: + view_paths.find_template(layout.to_s =~ /layouts\// ? layout : "layouts/#{layout}", format, html_fallback) rescue ActionView::MissingTemplate raise if Mime::Type.lookup_by_extension(format.to_s).html? end @@ -234,7 +234,7 @@ module ActionController #:nodoc: when NilClass, TrueClass active_layout if action_has_layout? && candidate_for_layout?(:template => default_template_name) else - active_layout(layout) + active_layout(layout, :html_fallback => true) end else active_layout if action_has_layout? && candidate_for_layout?(options) diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 02ae8ac..e5bbfe9 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -313,6 +313,10 @@ class TestController < ActionController::Base def render_implicit_js_template_without_layout end + def render_html_explicit_template_and_layout + render :template => 'test/render_implicit_html_template_from_xhr_request', :layout => 'layouts/default_html' + end + def formatted_html_erb end @@ -720,6 +724,8 @@ class TestController < ActionController::Base "delete_with_js", "update_page", "update_page_with_instance_variables" "layouts/standard" + when "render_implicit_js_template_without_layout" + "layouts/default_html" when "action_talk_to_layout", "layout_overriding_layout" "layouts/talk_from_action" when "render_implicit_html_template_from_xhr_request" @@ -817,6 +823,11 @@ class RenderTest < ActionController::TestCase assert_equal "hello world, I'm here!", @response.body end + def test_xhr_with_render_text_and_layout + xhr :get, :render_text_hello_world_with_layout + assert_equal "hello world, I'm here!", @response.body + end + def test_do_with_render_action_and_layout_false get :hello_world_with_layout_false assert_equal 'Hello world!', @response.body @@ -1056,6 +1067,11 @@ class RenderTest < ActionController::TestCase assert_equal "XHR!\nHello HTML!", @response.body end + def test_should_render_explicit_html_template_with_html_layout + xhr :get, :render_html_explicit_template_and_layout + assert_equal "Hello HTML!\n", @response.body + end + def test_should_implicitly_render_js_template_without_layout get :render_implicit_js_template_without_layout, :format => :js assert_no_match //, @response.body diff --git a/actionpack/test/fixtures/layouts/default_html.html.erb b/actionpack/test/fixtures/layouts/default_html.html.erb new file mode 100644 index 0000000..edd7191 --- /dev/null +++ b/actionpack/test/fixtures/layouts/default_html.html.erb @@ -0,0 +1 @@ +<%= @content_for_layout %> -- 1.5.3.1