From f6972d690423eef0287b021187960eed17924513 Mon Sep 17 00:00:00 2001 From: Diego Algorta Date: Mon, 10 May 2010 01:54:19 -0300 Subject: [PATCH 1/2] Change private variable name --- actionpack/lib/abstract_controller/layouts.rb | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 09928ee..4df97ac 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -172,7 +172,7 @@ module AbstractController module ClassMethods def inherited(klass) super - klass.instance_variable_set(:@parent_layout, @_layout) + klass.instance_variable_set(:@_parent_layout, @_layout) klass._write_layout_method end @@ -347,7 +347,7 @@ module AbstractController if action_has_layout? layout_name = _layout else - layout_name = self.class.instance_variable_get(:@parent_layout) + layout_name = self.class.instance_variable_get(:@_parent_layout) end rescue NameError => e raise NoMethodError, -- 1.6.3.3 From 54a2928cd2d5fa825fccd9205099fabad7a46dc5 Mon Sep 17 00:00:00 2001 From: Diego Algorta Date: Mon, 10 May 2010 01:55:26 -0300 Subject: [PATCH 2/2] Fix documentation and add 2 more tests --- actionpack/lib/abstract_controller/layouts.rb | 4 +- actionpack/test/abstract/layouts_test.rb | 30 ++++++++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 4df97ac..71c0706 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -136,8 +136,8 @@ module AbstractController # # end # - # This will assign "weblog_standard" as the WeblogController's layout except for the +rss+ action, which will not wrap a layout - # around the rendered view. + # This will assign "weblog_standard" as the WeblogController's layout except for the +rss+ action, which will use whatever layout + # applies from the superclass. # # Both the :only and :except condition can accept an arbitrary number of method references, so # #:except => [ :rss, :text_only ] is valid, as is :except => :rss. diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb index 86f77d2..bd2ed55 100644 --- a/actionpack/test/abstract/layouts_test.rb +++ b/actionpack/test/abstract/layouts_test.rb @@ -12,6 +12,7 @@ module AbstractControllerTests "layouts/hello.erb" => "With String <%= yield %>", "layouts/hello_override.erb" => "With Override <%= yield %>", "layouts/will_only_show_on_index.erb" => "I'm in index <%= yield %>", + "layouts/will_not_show_on_new.erb" => "I'm not in new <%= yield %>", "layouts/overwrite.erb" => "Overwrite <%= yield %>", "layouts/with_false_layout.erb" => "False Layout <%= yield %>", "abstract_controller_tests/layouts/with_string_implied_child.erb" => @@ -58,13 +59,20 @@ module AbstractControllerTests layout "hello_override" end - class WithStringOverriddenChildWithCondition < WithString + class WithStringOverriddenChildWithOnlyCondition < WithString layout "will_only_show_on_index", :only => :index def new render :template => ActionView::Template::Text.new("Hello string!") end end + class WithStringOverriddenChildWithExceptCondition < WithString + layout "will_not_show_on_new", :except => :new + def new + render :template => ActionView::Template::Text.new("Hello string!") + end + end + class WithNilChild < WithString layout nil end @@ -252,14 +260,26 @@ module AbstractControllerTests assert_equal "With Override Hello string!", controller.response_body end - test "when a child controller has specified a layout with a condition, use that layout and not the parent controller in the specified conditon action" do - controller = WithStringOverriddenChildWithCondition.new + test "when a child controller has specified a layout with an 'only' condition, use that layout and not the parent controller in the specified conditon action" do + controller = WithStringOverriddenChildWithOnlyCondition.new controller.process(:index) assert_equal "I'm in index Hello string!", controller.response_body end - test "when a child controller has specified a layout with a condition, and the action does not fit in the condition, it should render the parent action" do - controller = WithStringOverriddenChildWithCondition.new + test "when a child controller has specified a layout with an 'only' condition, and the action does not fit in the condition, it should render the parent action" do + controller = WithStringOverriddenChildWithOnlyCondition.new + controller.process(:new) + assert_equal "With String Hello string!", controller.response_body + end + + test "when a child controller has specified a layout with a 'except' condition, and the action does not fit in the condition, it should render the parent action" do + controller = WithStringOverriddenChildWithExceptCondition.new + controller.process(:index) + assert_equal "I'm not in new Hello string!", controller.response_body + end + + test "when a child controller has specified a layout with a 'except' condition, use that layout and not the parent controller in the specified conditon action" do + controller = WithStringOverriddenChildWithExceptCondition.new controller.process(:new) assert_equal "With String Hello string!", controller.response_body end -- 1.6.3.3