From c51aa9f6f2c361e1efc53020028592564318e8a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Emin=20=C4=B0NA=C3=87?= Date: Tue, 7 Apr 2015 17:18:59 +0300 Subject: [PATCH] fix for actionview parent layout bug This commit fixes issue #19626 Don't need to check layout conditions if there is no condition test for parent layout bug fix --- actionview/lib/action_view/layouts.rb | 25 +++++++++++++------ .../test/actionpack/controller/layout_test.rb | 14 +++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/actionview/lib/action_view/layouts.rb b/actionview/lib/action_view/layouts.rb index 9d636c8c9e..1fc609f2cd 100644 --- a/actionview/lib/action_view/layouts.rb +++ b/actionview/lib/action_view/layouts.rb @@ -315,16 +315,25 @@ module ActionView name_clause end - self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 - def _layout - if _conditional_layout? + if self._layout_conditions.empty? + self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 + def _layout #{layout_definition} - else - #{name_clause} end - end - private :_layout - RUBY + private :_layout + RUBY + else + self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 + def _layout + if _conditional_layout? + #{layout_definition} + else + #{name_clause} + end + end + private :_layout + RUBY + end end private diff --git a/actionview/test/actionpack/controller/layout_test.rb b/actionview/test/actionpack/controller/layout_test.rb index 7b8a83e2fe..64ab125637 100644 --- a/actionview/test/actionpack/controller/layout_test.rb +++ b/actionview/test/actionpack/controller/layout_test.rb @@ -122,6 +122,14 @@ class PrependsViewPathController < LayoutTest end end +class ParentController < LayoutTest + layout 'item' +end + +class ChildController < ParentController + layout 'layout_test', only: :hello +end + class OnlyLayoutController < LayoutTest layout 'item', :only => "hello" end @@ -225,6 +233,12 @@ class LayoutSetInResponseTest < ActionController::TestCase get :hello assert_equal "layout_test.erb hello.erb", @response.body.strip end + + def test_respect_to_parent_layout + @controller = ChildController.new + get :goodbye + assert_template :layout => "layouts/item" + end end class SetsNonExistentLayoutFile < LayoutTest