aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-03-27 16:09:12 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-03-27 16:09:12 -0300
commite7438501d69f266aca4ba5d6f511b9fe5264862f (patch)
tree07964889905ad1a6877ea62aec3b83e19e6aab5c /actionpack/test
parent125098549841fe39b788dc6c227eae6cf69a4ba7 (diff)
parentef27bba63d93453dee26e2decfca80659f2da735 (diff)
downloadrails-e7438501d69f266aca4ba5d6f511b9fe5264862f.tar.gz
rails-e7438501d69f266aca4ba5d6f511b9fe5264862f.tar.bz2
rails-e7438501d69f266aca4ba5d6f511b9fe5264862f.zip
Merge pull request #8458 from lucisferre/improve-layout-override-fallback-behavior
Provides standard layout lookup behavior for method and proc cases Conflicts: actionpack/CHANGELOG.md
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/abstract/layouts_test.rb14
-rw-r--r--actionpack/test/controller/layout_test.rb24
2 files changed, 38 insertions, 0 deletions
diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb
index 558a45b87f..70688d7267 100644
--- a/actionpack/test/abstract/layouts_test.rb
+++ b/actionpack/test/abstract/layouts_test.rb
@@ -79,6 +79,14 @@ module AbstractControllerTests
end
end
+ class WithProcReturningNil < Base
+ layout proc { |c| nil }
+
+ def index
+ render template: ActionView::Template::Text.new("Hello nil!")
+ end
+ end
+
class WithZeroArityProc < Base
layout proc { "overwrite" }
@@ -249,6 +257,12 @@ module AbstractControllerTests
assert_equal "Overwrite Hello proc!", controller.response_body
end
+ test "when layout is specified as a proc and the proc retuns nil, don't use a layout" do
+ controller = WithProcReturningNil.new
+ controller.process(:index)
+ assert_equal "Hello nil!", controller.response_body
+ end
+
test "when layout is specified as a proc without parameters it works just the same" do
controller = WithZeroArityProc.new
controller.process(:index)
diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb
index 71bcfd664e..a61a1fe99d 100644
--- a/actionpack/test/controller/layout_test.rb
+++ b/actionpack/test/controller/layout_test.rb
@@ -94,6 +94,18 @@ class HasOwnLayoutController < LayoutTest
layout 'item'
end
+class HasNilLayoutSymbol < LayoutTest
+ layout :nilz
+
+ def nilz
+ nil
+ end
+end
+
+class HasNilLayoutProc < LayoutTest
+ layout proc { |c| nil }
+end
+
class PrependsViewPathController < LayoutTest
def hello
prepend_view_path File.dirname(__FILE__) + '/../fixtures/layout_tests/alt/'
@@ -142,6 +154,18 @@ class LayoutSetInResponseTest < ActionController::TestCase
assert_template :layout => "layouts/item"
end
+ def test_layout_symbol_set_in_controller_returning_nil_falls_back_to_default
+ @controller = HasNilLayoutSymbol.new
+ get :hello
+ assert_template layout: "layouts/layout_test"
+ end
+
+ def test_layout_proc_set_in_controller_returning_nil_falls_back_to_default
+ @controller = HasNilLayoutProc.new
+ get :hello
+ assert_template layout: "layouts/layout_test"
+ end
+
def test_layout_only_exception_when_included
@controller = OnlyLayoutController.new
get :hello