aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/abstract_controller
diff options
context:
space:
mode:
authorYehuda Katz and Carl Lerche <wycats@gmail.com>2009-04-07 15:54:02 -0700
committerYehuda Katz and Carl Lerche <wycats@gmail.com>2009-04-07 15:54:02 -0700
commit95c9718118bc0342ddb320f23b5e0a17fb12b7ad (patch)
tree131f46b4a147a492def006c6190c58a7e0abd057 /actionpack/test/abstract_controller
parentc1aa5b0e14cd4bd27a5d8bd85cf7c36fa5911830 (diff)
downloadrails-95c9718118bc0342ddb320f23b5e0a17fb12b7ad.tar.gz
rails-95c9718118bc0342ddb320f23b5e0a17fb12b7ad.tar.bz2
rails-95c9718118bc0342ddb320f23b5e0a17fb12b7ad.zip
Layouts work in AbstractController. Add support for the rspec runner for T::U
Diffstat (limited to 'actionpack/test/abstract_controller')
-rw-r--r--actionpack/test/abstract_controller/layouts_test.rb119
1 files changed, 92 insertions, 27 deletions
diff --git a/actionpack/test/abstract_controller/layouts_test.rb b/actionpack/test/abstract_controller/layouts_test.rb
index ec8faffc51..541d126958 100644
--- a/actionpack/test/abstract_controller/layouts_test.rb
+++ b/actionpack/test/abstract_controller/layouts_test.rb
@@ -9,9 +9,12 @@ module AbstractControllerTests
use AbstractController::Layouts
self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
- "layouts/hello.erb" => "With String <%= yield %>",
- "layouts/omg.erb" => "OMGHI2U <%= yield %>",
- "layouts/with_false_layout.erb" => "False Layout <%= yield %>"
+ "layouts/hello.erb" => "With String <%= yield %>",
+ "layouts/hello_override.erb" => "With Override <%= yield %>",
+ "layouts/abstract_controller_tests/layouts/with_string_implied_child.erb" =>
+ "With Implied <%= yield %>",
+ "layouts/omg.erb" => "OMGHI2U <%= yield %>",
+ "layouts/with_false_layout.erb" => "False Layout <%= yield %>"
)]
def self.controller_path
@@ -42,6 +45,23 @@ module AbstractControllerTests
end
end
+ class WithStringChild < WithString
+ end
+
+ class WithStringOverriddenChild < WithString
+ layout "hello_override"
+ end
+
+ class WithNilChild < WithString
+ layout nil
+ end
+
+ class WithStringImpliedChild < WithString
+ end
+
+ class WithChildOfImplied < WithStringImpliedChild
+ end
+
class WithSymbol < Base
layout :hello
@@ -66,6 +86,36 @@ module AbstractControllerTests
end
end
+ class WithSymbolReturningNil < Base
+ layout :nilz
+
+ def index
+ render :_template => ActionView::TextTemplate.new("Hello nilz!")
+ end
+
+ def nilz() end
+ end
+
+ class WithSymbolReturningObj < Base
+ layout :objekt
+
+ def index
+ render :_template => ActionView::TextTemplate.new("Hello nilz!")
+ end
+
+ def objekt
+ Object.new
+ end
+ end
+
+ class WithSymbolAndNoMethod < Base
+ layout :omg_no_method
+
+ def index
+ render :_template => ActionView::TextTemplate.new("Hello boom!")
+ end
+ end
+
class WithMissingLayout < Base
layout "missing"
@@ -82,6 +132,24 @@ module AbstractControllerTests
end
end
+ class WithNilLayout < Base
+ layout nil
+
+ def index
+ render :_template => ActionView::TextTemplate.new("Hello nil!")
+ end
+ end
+
+ # TODO Move to bootloader
+ AbstractController::Base.subclasses.each do |klass|
+ klass = klass.constantize
+ next unless klass < AbstractController::Layouts
+ p klass
+ klass.class_eval do
+ _write_layout_method
+ end
+ end
+
class TestBase < ActiveSupport::TestCase
test "when no layout is specified, and no default is available, render without a layout" do
result = Blank.process(:index)
@@ -103,7 +171,8 @@ module AbstractControllerTests
end
test "when layout is specified as nil, do not use a layout" do
- pending
+ result = WithNilLayout.process(:index)
+ assert_equal "Hello nil!", result.response_obj[:body]
end
test "when layout is specified as a symbol, call the requested method and use the layout returned" do
@@ -112,47 +181,43 @@ module AbstractControllerTests
end
test "when layout is specified as a symbol and the method returns nil, don't use a layout" do
- pending
+ result = WithSymbolReturningNil.process(:index)
+ assert_equal "Hello nilz!", result.response_obj[:body]
end
test "when the layout is specified as a symbol and the method doesn't exist, raise an exception" do
- pending
+ assert_raises(NoMethodError, /:nilz/) { WithSymbolAndNoMethod.process(:index) }
end
test "when the layout is specified as a symbol and the method returns something besides a string/false/nil, raise an exception" do
- pending
+ assert_raises(ArgumentError) { WithSymbolReturningObj.process(:index) }
end
test "when a child controller does not have a layout, use the parent controller layout" do
- pending
+ result = WithStringChild.process(:index)
+ assert_equal "With String Hello string!", result.response_obj[:body]
end
test "when a child controller has specified a layout, use that layout and not the parent controller layout" do
- pending
+ result = WithStringOverriddenChild.process(:index)
+ assert_equal "With Override Hello string!", result.response_obj[:body]
end
test "when a child controller has an implied layout, use that layout and not the parent controller layout" do
- pending
+ result = WithStringImpliedChild.process(:index)
+ assert_equal "With Implied Hello string!", result.response_obj[:body]
end
test "when a child controller specifies layout nil, do not use the parent layout" do
- pending
- end
-
- test "when a child controller has an implied layout, use that layout instead of the parent controller layout" do
- pending
- 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
- pending
- end
-
- test "Raise ArgumentError if layout is called with a bad argument" do
- pending
- end
+ result = WithNilChild.process(:index)
+ assert_equal "Hello string!", result.response_obj[: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
+ result = WithChildOfImplied.process(:index)
+ assert_equal "With Implied Hello string!", result.response_obj[:body]
+ end
end
end
end \ No newline at end of file