Permalink
Browse files

Add a test case for layout nil.

  • Loading branch information...
1 parent e97aa2c commit f29b4a02fddb71d15fe1ee5f58096699caf61916 @josevalim josevalim committed Dec 20, 2011
Showing with 17 additions and 12 deletions.
  1. +2 −1 actionpack/lib/abstract_controller/layouts.rb
  2. +15 −11 actionpack/test/abstract/layouts_test.rb
@@ -241,6 +241,7 @@ def conditional_layout?
# the template name
# false:: There is no layout
# true:: raise an ArgumentError
+ # nil:: Force default layout behavior with inheritance
#
# ==== Parameters
# * <tt>layout</tt> - The layout to use.
@@ -254,7 +255,7 @@ def layout(layout, conditions = {})
conditions.each {|k, v| conditions[k] = Array(v).map {|a| a.to_s} }
self._layout_conditions = conditions
- @_layout = layout || false # Converts nil to false
+ @_layout = layout
_write_layout_method
end
@@ -14,7 +14,10 @@ class Base < AbstractController::Base
"layouts/overwrite.erb" => "Overwrite <%= yield %>",
"layouts/with_false_layout.erb" => "False Layout <%= yield %>",
"abstract_controller_tests/layouts/with_string_implied_child.erb" =>
- "With Implied <%= yield %>"
+ "With Implied <%= yield %>",
+ "abstract_controller_tests/layouts/with_grand_child_of_implied.erb" =>
+ "With Grand Child <%= yield %>"
+
)]
end
@@ -57,16 +60,16 @@ class WithStringOverriddenChild < WithString
layout "hello_override"
end
- class WithNilChild < WithString
- layout nil
- end
-
class WithStringImpliedChild < WithString
end
class WithChildOfImplied < WithStringImpliedChild
end
+ class WithGrandChildOfImplied < WithStringImpliedChild
+ layout nil
+ end
+
class WithProc < Base
layout proc { |c| "overwrite" }
@@ -262,19 +265,20 @@ class TestBase < ActiveSupport::TestCase
assert_equal "With Implied Hello string!", controller.response_body
end
- test "when a child controller specifies layout nil, do not use the parent layout" do
- controller = WithNilChild.new
- controller.process(:index)
- assert_equal "Hello string!", controller.response_body
- end
-
test "when a grandchild has no layout specified, the child has an implied layout, and the " \
"parent has specified a layout, use the child controller layout" do
controller = WithChildOfImplied.new
assert_deprecated { controller.process(:index) }
assert_equal "With Implied Hello string!", controller.response_body
end
+ test "when a grandchild has nil layout specified, the child has an implied layout, and the " \
+ "parent has specified a layout, use the child controller layout" do
+ controller = WithGrandChildOfImplied.new
+ controller.process(:index)
+ assert_equal "With Grand Child Hello string!", controller.response_body
+ end
+
test "raises an exception when specifying layout true" do
assert_raises ArgumentError do
Object.class_eval do

0 comments on commit f29b4a0

Please sign in to comment.