aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/abstract_controller/abstract_controller_test.rb
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-02-27 11:42:13 -0800
committerYehuda Katz <wycats@gmail.com>2009-02-27 11:42:13 -0800
commitd1157e7242d248b37546800bf7816c3035b56ce8 (patch)
treea60dd14e012ae0d7d758e4cbb3a16724c0ca9596 /actionpack/test/abstract_controller/abstract_controller_test.rb
parentb1f078bddfecd40cce47b7db738620f2df2219c9 (diff)
downloadrails-d1157e7242d248b37546800bf7816c3035b56ce8.tar.gz
rails-d1157e7242d248b37546800bf7816c3035b56ce8.tar.bz2
rails-d1157e7242d248b37546800bf7816c3035b56ce8.zip
AbstractController now supports layouts and rendering
Diffstat (limited to 'actionpack/test/abstract_controller/abstract_controller_test.rb')
-rw-r--r--actionpack/test/abstract_controller/abstract_controller_test.rb101
1 files changed, 100 insertions, 1 deletions
diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb
index a5026fb0da..4834f8b7bb 100644
--- a/actionpack/test/abstract_controller/abstract_controller_test.rb
+++ b/actionpack/test/abstract_controller/abstract_controller_test.rb
@@ -5,6 +5,7 @@ require 'test/unit'
require 'active_support'
require 'active_support/test_case'
require 'action_controller'
+require 'action_view/base'
begin
require 'ruby-debug'
@@ -16,6 +17,7 @@ end
require 'action_controller/abstract/base'
require 'action_controller/abstract/renderer'
+require 'action_controller/abstract/layouts'
module AbstractController
module Testing
@@ -27,7 +29,7 @@ module AbstractController
def index
self.response_body = "Hello world"
"Something else"
- end
+ end
end
class TestBasic < ActiveSupport::TestCase
@@ -47,6 +49,15 @@ module AbstractController
def index
render "index.erb"
end
+
+ def action_with_ivars
+ @my_ivar = "Hello"
+ render "action_with_ivars.erb"
+ end
+
+ def naked_render
+ render
+ end
end
class TestRenderer < ActiveSupport::TestCase
@@ -54,6 +65,94 @@ module AbstractController
result = Me2.process(:index)
assert_equal "Hello from index.erb", result.response_obj[:body]
end
+
+ test "rendering passes ivars to the view" do
+ result = Me2.process(:action_with_ivars)
+ assert_equal "Hello from index_with_ivars.erb", result.response_obj[:body]
+ end
+
+ test "rendering with no template name" do
+ result = Me2.process(:naked_render)
+ assert_equal "Hello from naked_render.erb", result.response_obj[:body]
+ end
+ end
+
+ class PrefixedViews < RenderingController
+ private
+ def self.prefix
+ name.underscore
+ end
+
+ def _prefix
+ self.class.prefix
+ end
+ end
+
+ class Me3 < PrefixedViews
+ def index
+ render
+ end
+
+ def formatted
+ self.formats = [:html]
+ render
+ end
+ end
+
+ class TestPrefixedViews < ActiveSupport::TestCase
+ test "templates are located inside their 'prefix' folder" do
+ result = Me3.process(:index)
+ assert_equal "Hello from me3/index.erb", result.response_obj[:body]
+ end
+
+ test "templates included their format" do
+ result = Me3.process(:formatted)
+ assert_equal "Hello from me3/formatted.html.erb", result.response_obj[:body]
+ end
+ end
+
+ class WithLayouts < PrefixedViews
+ include Layouts
+
+ private
+ def self.layout(formats)
+ begin
+ view_paths.find_by_parts(name.underscore, formats, "layouts")
+ rescue ActionView::MissingTemplate
+ begin
+ view_paths.find_by_parts("application", formats, "layouts")
+ rescue ActionView::MissingTemplate
+ end
+ end
+ end
+
+ def _layout
+ self.class.layout(formats)
+ end
+ end
+
+ class Me4 < WithLayouts
+ def index
+ render
+ end
+ end
+
+ class Me5 < WithLayouts
+ def index
+ render
+ end
+ end
+
+ class TestLayouts < ActiveSupport::TestCase
+ test "layouts are included" do
+ result = Me4.process(:index)
+ assert_equal "Me4 Enter : Hello from me4/index.erb : Exit", result.response_obj[:body]
+ end
+
+ test "it can fall back to the application layout" do
+ result = Me5.process(:index)
+ assert_equal "Application Enter : Hello from me5/index.erb : Exit", result.response_obj[:body]
+ end
end
end