aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/abstract_controller/layouts_test.rb119
-rw-r--r--actionpack/test/new_base/test_helper.rb19
2 files changed, 93 insertions, 45 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
diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb
index 9058060059..5edd7b4f63 100644
--- a/actionpack/test/new_base/test_helper.rb
+++ b/actionpack/test/new_base/test_helper.rb
@@ -70,24 +70,7 @@ class Rack::TestCase < ActiveSupport::TestCase
ActionController::Routing.use_controllers!(controllers)
end
-
- unless method_defined?(:describe)
- def self.describe(text)
- class_eval <<-RUBY_EVAL
- def self.name
- "#{text}"
- end
- RUBY_EVAL
- end
- end
-
- if defined?(Spec)
- class << self
- undef test
- alias_method :test, :it
- end
- end
-
+
def app
@app ||= ActionController::Dispatcher.new
end