aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/new_base
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-05-12 16:13:00 -0300
committerEmilio Tagua <miloops@gmail.com>2009-05-12 16:13:00 -0300
commit0048897a417774f7e5a0c8c9e82fc8684f94ebc1 (patch)
tree8df248dab434bdaac61ea60249d4630958260eed /actionpack/test/new_base
parent6c7d8cb8ac9e6b6775e9a54ef0be62dbaab592f5 (diff)
parent22c5667c2ef46d6723c1805d3adc52dc8e92429b (diff)
downloadrails-0048897a417774f7e5a0c8c9e82fc8684f94ebc1.tar.gz
rails-0048897a417774f7e5a0c8c9e82fc8684f94ebc1.tar.bz2
rails-0048897a417774f7e5a0c8c9e82fc8684f94ebc1.zip
Merge commit 'rails/master'
Diffstat (limited to 'actionpack/test/new_base')
-rw-r--r--actionpack/test/new_base/base_test.rb51
-rw-r--r--actionpack/test/new_base/content_type_test.rb111
-rw-r--r--actionpack/test/new_base/etag_test.rb47
-rw-r--r--actionpack/test/new_base/render_action_test.rb14
-rw-r--r--actionpack/test/new_base/render_implicit_action_test.rb30
-rw-r--r--actionpack/test/new_base/render_layout_test.rb22
-rw-r--r--actionpack/test/new_base/render_template_test.rb92
-rw-r--r--actionpack/test/new_base/render_test.rb88
-rw-r--r--actionpack/test/new_base/render_text_test.rb79
-rw-r--r--actionpack/test/new_base/test_helper.rb43
10 files changed, 423 insertions, 154 deletions
diff --git a/actionpack/test/new_base/base_test.rb b/actionpack/test/new_base/base_test.rb
index 4f46cb6492..a32653f128 100644
--- a/actionpack/test/new_base/base_test.rb
+++ b/actionpack/test/new_base/base_test.rb
@@ -1,8 +1,8 @@
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
# Tests the controller dispatching happy path
-module HappyPath
- class SimpleDispatchController < ActionController::Base2
+module Dispatching
+ class SimpleController < ActionController::Base
def index
render :text => "success"
end
@@ -23,7 +23,7 @@ module HappyPath
class TestSimpleDispatch < SimpleRouteCase
- get "/happy_path/simple_dispatch/index"
+ get "/dispatching/simple/index"
test "sets the body" do
assert_body "success"
@@ -34,57 +34,56 @@ module HappyPath
end
test "sets the content type" do
- assert_content_type Mime::HTML
+ assert_content_type "text/html; charset=utf-8"
end
test "sets the content length" do
- assert_header "Content-Length", 7
+ assert_header "Content-Length", "7"
end
end
# :api: plugin
class TestDirectResponseMod < SimpleRouteCase
- get "/happy_path/simple_dispatch/modify_response_body"
+ get "/dispatching/simple/modify_response_body"
test "sets the body" do
assert_body "success"
end
test "setting the body manually sets the content length" do
- assert_header "Content-Length", 7
+ assert_header "Content-Length", "7"
end
end
# :api: plugin
class TestDirectResponseModTwice < SimpleRouteCase
- get "/happy_path/simple_dispatch/modify_response_body_twice"
+ get "/dispatching/simple/modify_response_body_twice"
test "self.response_body= returns the body being set" do
assert_body "success!"
end
test "updating the response body updates the content length" do
- assert_header "Content-Length", 8
+ assert_header "Content-Length", "8"
end
end
-end
-
-
-class EmptyController < ActionController::Base2 ; end
-module Submodule
- class ContainedEmptyController < ActionController::Base2 ; end
-end
+
+ class EmptyController < ActionController::Base ; end
+ module Submodule
+ class ContainedEmptyController < ActionController::Base ; end
+ end
-class ControllerClassTests < Test::Unit::TestCase
- def test_controller_path
- assert_equal 'empty', EmptyController.controller_path
- assert_equal EmptyController.controller_path, EmptyController.new.controller_path
- assert_equal 'submodule/contained_empty', Submodule::ContainedEmptyController.controller_path
- assert_equal Submodule::ContainedEmptyController.controller_path, Submodule::ContainedEmptyController.new.controller_path
+ class ControllerClassTests < Test::Unit::TestCase
+ def test_controller_path
+ assert_equal 'dispatching/empty', EmptyController.controller_path
+ assert_equal EmptyController.controller_path, EmptyController.new.controller_path
+ assert_equal 'dispatching/submodule/contained_empty', Submodule::ContainedEmptyController.controller_path
+ assert_equal Submodule::ContainedEmptyController.controller_path, Submodule::ContainedEmptyController.new.controller_path
+ end
+ def test_controller_name
+ assert_equal 'empty', EmptyController.controller_name
+ assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name
+ end
end
- def test_controller_name
- assert_equal 'empty', EmptyController.controller_name
- assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name
- end
end \ No newline at end of file
diff --git a/actionpack/test/new_base/content_type_test.rb b/actionpack/test/new_base/content_type_test.rb
new file mode 100644
index 0000000000..a5c04e9cb6
--- /dev/null
+++ b/actionpack/test/new_base/content_type_test.rb
@@ -0,0 +1,111 @@
+require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+
+module ContentType
+ class BaseController < ActionController::Base
+ def index
+ render :text => "Hello world!"
+ end
+
+ def set_on_response_obj
+ response.content_type = Mime::RSS
+ render :text => "Hello world!"
+ end
+
+ def set_on_render
+ render :text => "Hello world!", :content_type => Mime::RSS
+ end
+ end
+
+ class TestDefault < SimpleRouteCase
+ describe "a default response is HTML and UTF8"
+
+ get "/content_type/base"
+ assert_body "Hello world!"
+ assert_header "Content-Type", "text/html; charset=utf-8"
+ end
+
+ class TestSetOnResponseObj < SimpleRouteCase
+ describe "setting the content type of the response directly on the response object"
+
+ get "/content_type/base/set_on_response_obj"
+ assert_body "Hello world!"
+ assert_header "Content-Type", "application/rss+xml; charset=utf-8"
+ end
+
+ class TestSetOnRender < SimpleRouteCase
+ describe "setting the content type of the response as an option to render"
+
+ get "/content_type/base/set_on_render"
+ assert_body "Hello world!"
+ assert_header "Content-Type", "application/rss+xml; charset=utf-8"
+ end
+
+ class ImpliedController < ActionController::Base
+ self.view_paths = [ActionView::Template::FixturePath.new(
+ "content_type/implied/i_am_html_erb.html.erb" => "Hello world!",
+ "content_type/implied/i_am_xml_erb.xml.erb" => "<xml>Hello world!</xml>",
+ "content_type/implied/i_am_html_builder.html.builder" => "xml.p 'Hello'",
+ "content_type/implied/i_am_xml_builder.xml.builder" => "xml.awesome 'Hello'"
+ )]
+
+ def i_am_html_erb() end
+ def i_am_xml_erb() end
+ def i_am_html_builder() end
+ def i_am_xml_builder() end
+ end
+
+ class TestImpliedController < SimpleRouteCase
+ describe "the template's mime type is used if no content_type is specified"
+
+ test "sets Content-Type as text/html when rendering *.html.erb" do
+ get "/content_type/implied/i_am_html_erb"
+ assert_header "Content-Type", "text/html; charset=utf-8"
+ end
+
+ test "sets Content-Type as application/xml when rendering *.xml.erb" do
+ get "/content_type/implied/i_am_xml_erb"
+ assert_header "Content-Type", "application/xml; charset=utf-8"
+ end
+
+ test "sets Content-Type as text/html when rendering *.html.builder" do
+ get "/content_type/implied/i_am_html_builder"
+ assert_header "Content-Type", "text/html; charset=utf-8"
+ end
+
+ test "sets Content-Type as application/xml when rendering *.xml.builder" do
+ get "/content_type/implied/i_am_xml_builder"
+ assert_header "Content-Type", "application/xml; charset=utf-8"
+ end
+
+ end
+end
+
+module Charset
+ class BaseController < ActionController::Base
+ def set_on_response_obj
+ response.charset = "utf-16"
+ render :text => "Hello world!"
+ end
+
+ def set_as_nil_on_response_obj
+ response.charset = nil
+ render :text => "Hello world!"
+ end
+ end
+
+ class TestSetOnResponseObj < SimpleRouteCase
+ describe "setting the charset of the response directly on the response object"
+
+ get "/charset/base/set_on_response_obj"
+ assert_body "Hello world!"
+ assert_header "Content-Type", "text/html; charset=utf-16"
+ end
+
+ class TestSetAsNilOnResponseObj < SimpleRouteCase
+ describe "setting the charset of the response as nil directly on the response object"
+
+ get "/charset/base/set_as_nil_on_response_obj"
+ assert_body "Hello world!"
+ assert_header "Content-Type", "text/html; charset=utf-8"
+ end
+end \ No newline at end of file
diff --git a/actionpack/test/new_base/etag_test.rb b/actionpack/test/new_base/etag_test.rb
new file mode 100644
index 0000000000..7af5febfb3
--- /dev/null
+++ b/actionpack/test/new_base/etag_test.rb
@@ -0,0 +1,47 @@
+require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+
+module Etags
+
+ class BasicController < ActionController::Base
+
+ self.view_paths = [ActionView::Template::FixturePath.new(
+ "etags/basic/base.html.erb" => "Hello from without_layout.html.erb",
+ "layouts/etags.html.erb" => "teh <%= yield %> tagz"
+ )]
+
+ def without_layout
+ render :action => "base"
+ end
+
+ def with_layout
+ render :action => "base", :layout => "etag"
+ end
+
+ end
+
+ class TestBasic < SimpleRouteCase
+ describe "Rendering without any special etag options returns an etag that is an MD5 hash of its text"
+
+ test "an action without a layout" do
+ get "/etags/basic/without_layout"
+ body = "Hello from without_layout.html.erb"
+ assert_body body
+ assert_header "Etag", etag_for(body)
+ assert_status 200
+ end
+
+ test "an action with a layout" do
+ get "/etags/basic/with_layout"
+ body = "teh Hello from without_layout.html.erb tagz"
+ assert_body body
+ assert_header "Etag", etag_for(body)
+ assert_status 200
+ end
+
+ def etag_for(text)
+ %("#{Digest::MD5.hexdigest(text)}")
+ end
+ end
+
+
+end \ No newline at end of file
diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb
index 2bfb374a31..348d70381b 100644
--- a/actionpack/test/new_base/render_action_test.rb
+++ b/actionpack/test/new_base/render_action_test.rb
@@ -3,9 +3,9 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
module RenderAction
# This has no layout and it works
- class BasicController < ActionController::Base2
+ class BasicController < ActionController::Base
- self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
+ self.view_paths = [ActionView::Template::FixturePath.new(
"render_action/basic/hello_world.html.erb" => "Hello world!"
)]
@@ -129,7 +129,7 @@ module RenderActionWithApplicationLayout
class BasicController < ::ApplicationController
# Set the view path to an application view structure with layouts
- self.view_paths = self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
+ self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new(
"render_action_with_application_layout/basic/hello_world.html.erb" => "Hello World!",
"layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI",
"layouts/greetings.html.erb" => "Greetings <%= yield %> Bai"
@@ -203,8 +203,8 @@ end
module RenderActionWithControllerLayout
- class BasicController < ActionController::Base2
- self.view_paths = self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
+ class BasicController < ActionController::Base
+ self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new(
"render_action_with_controller_layout/basic/hello_world.html.erb" => "Hello World!",
"layouts/render_action_with_controller_layout/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI"
)]
@@ -266,8 +266,8 @@ end
module RenderActionWithBothLayouts
- class BasicController < ActionController::Base2
- self.view_paths = [ActionView::FixtureTemplate::FixturePath.new({
+ class BasicController < ActionController::Base
+ self.view_paths = [ActionView::Template::FixturePath.new({
"render_action_with_both_layouts/basic/hello_world.html.erb" => "Hello World!",
"layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI",
"layouts/render_action_with_both_layouts/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI"
diff --git a/actionpack/test/new_base/render_implicit_action_test.rb b/actionpack/test/new_base/render_implicit_action_test.rb
index 798505b539..58f5cec181 100644
--- a/actionpack/test/new_base/render_implicit_action_test.rb
+++ b/actionpack/test/new_base/render_implicit_action_test.rb
@@ -1,16 +1,28 @@
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
-module HappyPath
-
- class RenderImplicitActionController < ActionController::Base2
- # No actions yet, they are implicit
+module RenderImplicitAction
+ class SimpleController < ::ApplicationController
+ self.view_paths = [ActionView::Template::FixturePath.new(
+ "render_implicit_action/simple/hello_world.html.erb" => "Hello world!",
+ "render_implicit_action/simple/hyphen-ated.html.erb" => "Hello hyphen-ated!"
+ )]
+
+ def hello_world() end
end
- class TestRendersActionImplicitly < SimpleRouteCase
-
- test "renders action implicitly" do
- assert true
- end
+ class TestImplicitRender < SimpleRouteCase
+ describe "render a simple action with new explicit call to render"
+
+ get "/render_implicit_action/simple/hello_world"
+ assert_body "Hello world!"
+ assert_status 200
+ end
+ class TestImplicitWithSpecialCharactersRender < SimpleRouteCase
+ describe "render an action with a missing method and has special characters"
+
+ get "/render_implicit_action/simple/hyphen-ated"
+ assert_body "Hello hyphen-ated!"
+ assert_status 200
end
end \ No newline at end of file
diff --git a/actionpack/test/new_base/render_layout_test.rb b/actionpack/test/new_base/render_layout_test.rb
index facf67ea85..5d28926cc6 100644
--- a/actionpack/test/new_base/render_layout_test.rb
+++ b/actionpack/test/new_base/render_layout_test.rb
@@ -3,14 +3,23 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
module ControllerLayouts
class ImplicitController < ::ApplicationController
- self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
+ self.view_paths = [ActionView::Template::FixturePath.new(
"layouts/application.html.erb" => "OMG <%= yield %> KTHXBAI",
- "basic.html.erb" => "Hello world!"
+ "layouts/override.html.erb" => "Override! <%= yield %>",
+ "basic.html.erb" => "Hello world!"
)]
def index
render :template => "basic"
end
+
+ def override
+ render :template => "basic", :layout => "override"
+ end
+
+ def builder_override
+
+ end
end
class TestImplicitLayout < SimpleRouteCase
@@ -23,7 +32,7 @@ module ControllerLayouts
class ImplicitNameController < ::ApplicationController
- self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
+ self.view_paths = [ActionView::Template::FixturePath.new(
"layouts/controller_layouts/implicit_name.html.erb" => "OMGIMPLICIT <%= yield %> KTHXBAI",
"basic.html.erb" => "Hello world!"
)]
@@ -41,5 +50,10 @@ module ControllerLayouts
assert_status 200
end
-
+ class TestOverridingImplicitLayout < SimpleRouteCase
+ describe "overriding an implicit layout with render :layout option"
+
+ get "/controller_layouts/implicit/override"
+ assert_body "Override! Hello world!"
+ end
end \ No newline at end of file
diff --git a/actionpack/test/new_base/render_template_test.rb b/actionpack/test/new_base/render_template_test.rb
index c6c0269b40..c09eeb1926 100644
--- a/actionpack/test/new_base/render_template_test.rb
+++ b/actionpack/test/new_base/render_template_test.rb
@@ -1,43 +1,35 @@
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
-module HappyPath
-
- class RenderTemplateWithoutLayoutController < ActionController::Base2
+module RenderTemplate
+ class WithoutLayoutController < ActionController::Base
- self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
+ self.view_paths = [ActionView::Template::FixturePath.new(
"test/basic.html.erb" => "Hello from basic.html.erb",
- "shared.html.erb" => "Elastica"
+ "shared.html.erb" => "Elastica",
+ "locals.html.erb" => "The secret is <%= secret %>"
)]
- def render_hello_world
+ def index
render :template => "test/basic"
end
- def render_hello_world_with_forward_slash
- render :template => "/test/basic"
- end
-
- def render_template_in_top_directory
+ def in_top_directory
render :template => 'shared'
end
- def render_template_in_top_directory_with_slash
+ def in_top_directory_with_slash
render :template => '/shared'
end
- end
-
- class TestTemplateRenderWithoutLayout < SimpleRouteCase
- describe "rendering a normal template with full path without layout"
- get "/happy_path/render_template_without_layout/render_hello_world"
- assert_body "Hello from basic.html.erb"
- assert_status 200
+ def with_locals
+ render :template => "locals", :locals => { :secret => 'area51' }
+ end
end
- class TestTemplateRenderWithForwardSlash < SimpleRouteCase
- describe "rendering a normal template with full path starting with a leading slash"
+ class TestWithoutLayout < SimpleRouteCase
+ describe "rendering a normal template with full path without layout"
- get "/happy_path/render_template_without_layout/render_hello_world_with_forward_slash"
+ get "/render_template/without_layout"
assert_body "Hello from basic.html.erb"
assert_status 200
end
@@ -45,7 +37,7 @@ module HappyPath
class TestTemplateRenderInTopDirectory < SimpleRouteCase
describe "rendering a template not in a subdirectory"
- get "/happy_path/render_template_without_layout/render_template_in_top_directory"
+ get "/render_template/without_layout/in_top_directory"
assert_body "Elastica"
assert_status 200
end
@@ -53,37 +45,45 @@ module HappyPath
class TestTemplateRenderInTopDirectoryWithSlash < SimpleRouteCase
describe "rendering a template not in a subdirectory with a leading slash"
- get "/happy_path/render_template_without_layout/render_template_in_top_directory_with_slash"
+ get "/render_template/without_layout/in_top_directory_with_slash"
assert_body "Elastica"
assert_status 200
end
+
+ class TestTemplateRenderWithLocals < SimpleRouteCase
+ describe "rendering a template with local variables"
- class RenderTemplateWithLayoutController < ::ApplicationController
+ get "/render_template/without_layout/with_locals"
+ assert_body "The secret is area51"
+ assert_status 200
+ end
- self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
+ class WithLayoutController < ::ApplicationController
+
+ self.view_paths = [ActionView::Template::FixturePath.new(
"test/basic.html.erb" => "Hello from basic.html.erb",
"shared.html.erb" => "Elastica",
"layouts/application.html.erb" => "<%= yield %>, I'm here!",
"layouts/greetings.html.erb" => "<%= yield %>, I wish thee well."
)]
- def render_hello_world
+ def index
render :template => "test/basic"
end
- def render_hello_world_with_layout
+ def with_layout
render :template => "test/basic", :layout => true
end
- def render_hello_world_with_layout_false
+ def with_layout_false
render :template => "test/basic", :layout => false
end
- def render_hello_world_with_layout_nil
+ def with_layout_nil
render :template => "test/basic", :layout => nil
end
- def render_hello_world_with_custom_layout
+ def with_custom_layout
render :template => "test/basic", :layout => "greetings"
end
end
@@ -91,7 +91,7 @@ module HappyPath
class TestTemplateRenderWithLayout < SimpleRouteCase
describe "rendering a normal template with full path with layout"
- get "/happy_path/render_template_with_layout/render_hello_world"
+ get "/render_template/with_layout"
assert_body "Hello from basic.html.erb, I'm here!"
assert_status 200
end
@@ -99,7 +99,7 @@ module HappyPath
class TestTemplateRenderWithLayoutTrue < SimpleRouteCase
describe "rendering a normal template with full path with layout => :true"
- get "/happy_path/render_template_with_layout/render_hello_world_with_layout"
+ get "/render_template/with_layout/with_layout"
assert_body "Hello from basic.html.erb, I'm here!"
assert_status 200
end
@@ -107,7 +107,7 @@ module HappyPath
class TestTemplateRenderWithLayoutFalse < SimpleRouteCase
describe "rendering a normal template with full path with layout => :false"
- get "/happy_path/render_template_with_layout/render_hello_world_with_layout_false"
+ get "/render_template/with_layout/with_layout_false"
assert_body "Hello from basic.html.erb"
assert_status 200
end
@@ -115,7 +115,7 @@ module HappyPath
class TestTemplateRenderWithLayoutNil < SimpleRouteCase
describe "rendering a normal template with full path with layout => :nil"
- get "/happy_path/render_template_with_layout/render_hello_world_with_layout_nil"
+ get "/render_template/with_layout/with_layout_nil"
assert_body "Hello from basic.html.erb"
assert_status 200
end
@@ -123,11 +123,29 @@ module HappyPath
class TestTemplateRenderWithCustomLayout < SimpleRouteCase
describe "rendering a normal template with full path with layout => 'greetings'"
- get "/happy_path/render_template_with_layout/render_hello_world_with_custom_layout"
+ get "/render_template/with_layout/with_custom_layout"
assert_body "Hello from basic.html.erb, I wish thee well."
assert_status 200
end
-
+ module Compatibility
+ class WithoutLayoutController < ActionController::Base
+ self.view_paths = [ActionView::Template::FixturePath.new(
+ "test/basic.html.erb" => "Hello from basic.html.erb",
+ "shared.html.erb" => "Elastica"
+ )]
+ def with_forward_slash
+ render :template => "/test/basic"
+ end
+ end
+
+ class TestTemplateRenderWithForwardSlash < SimpleRouteCase
+ describe "rendering a normal template with full path starting with a leading slash"
+
+ get "/render_template/compatibility/without_layout/with_forward_slash"
+ assert_body "Hello from basic.html.erb"
+ assert_status 200
+ end
+ end
end \ No newline at end of file
diff --git a/actionpack/test/new_base/render_test.rb b/actionpack/test/new_base/render_test.rb
new file mode 100644
index 0000000000..b1867fdcc2
--- /dev/null
+++ b/actionpack/test/new_base/render_test.rb
@@ -0,0 +1,88 @@
+require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+
+module Render
+ class BlankRenderController < ActionController::Base
+ self.view_paths = [ActionView::Template::FixturePath.new(
+ "render/blank_render/index.html.erb" => "Hello world!",
+ "render/blank_render/access_request.html.erb" => "The request: <%= request.method.to_s.upcase %>",
+ "render/blank_render/access_action_name.html.erb" => "Action Name: <%= action_name %>",
+ "render/blank_render/access_controller_name.html.erb" => "Controller Name: <%= controller_name %>"
+ )]
+
+ def index
+ render
+ end
+
+ def access_request
+ render :action => "access_request"
+ end
+
+ def render_action_name
+ render :action => "access_action_name"
+ end
+
+ private
+
+ def secretz
+ render :text => "FAIL WHALE!"
+ end
+ end
+
+ class TestBlankRender < SimpleRouteCase
+ describe "Render with blank"
+
+ get "/render/blank_render"
+ assert_body "Hello world!"
+ assert_status 200
+ end
+
+ class DoubleRenderController < ActionController::Base
+ def index
+ render :text => "hello"
+ render :text => "world"
+ end
+ end
+
+ class TestBasic < SimpleRouteCase
+ describe "Rendering more than once"
+
+ test "raises an exception" do
+ assert_raises(AbstractController::DoubleRenderError) do
+ get "/render/double_render"
+ end
+ end
+ end
+
+ class TestOnlyRenderPublicActions < SimpleRouteCase
+ describe "Only public methods on actual controllers are callable actions"
+
+ test "raises an exception when a method of Object is called" do
+ assert_raises(AbstractController::ActionNotFound) do
+ get "/render/blank_render/clone"
+ end
+ end
+
+ test "raises an exception when a private method is called" do
+ assert_raises(AbstractController::ActionNotFound) do
+ get "/render/blank_render/secretz"
+ end
+ end
+ end
+
+ class TestVariousObjectsAvailableInView < SimpleRouteCase
+ test "The request object is accessible in the view" do
+ get "/render/blank_render/access_request"
+ assert_body "The request: GET"
+ end
+
+ test "The action_name is accessible in the view" do
+ get "/render/blank_render/render_action_name"
+ assert_body "Action Name: render_action_name"
+ end
+
+ test "The controller_name is accessible in the view" do
+ get "/render/blank_render/access_controller_name"
+ assert_body "Controller Name: blank_render"
+ end
+ end
+end \ No newline at end of file
diff --git a/actionpack/test/new_base/render_text_test.rb b/actionpack/test/new_base/render_text_test.rb
index a20ca5fb8c..39f2f7abbf 100644
--- a/actionpack/test/new_base/render_text_test.rb
+++ b/actionpack/test/new_base/render_text_test.rb
@@ -1,77 +1,82 @@
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
-class ApplicationController < ActionController::Base2
+class ApplicationController < ActionController::Base
end
-module HappyPath
-
- class RenderTextWithoutLayoutsController < ActionController::Base2
- self.view_paths = [ActionView::FixtureTemplate::FixturePath.new]
+module RenderText
+ class SimpleController < ActionController::Base
+ self.view_paths = [ActionView::Template::FixturePath.new]
- def render_hello_world
+ def index
render :text => "hello david"
end
end
- class RenderTextWithLayoutsController < ::ApplicationController
- self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
+ class TestSimpleTextRenderWithNoLayout < SimpleRouteCase
+ describe "Rendering text from a action with default options renders the text with the layout"
+
+ get "/render_text/simple"
+ assert_body "hello david"
+ assert_status 200
+ end
+
+ class WithLayoutController < ::ApplicationController
+ self.view_paths = [ActionView::Template::FixturePath.new(
"layouts/application.html.erb" => "<%= yield %>, I'm here!",
- "layouts/greetings.html.erb" => "<%= yield %>, I wish thee well."
+ "layouts/greetings.html.erb" => "<%= yield %>, I wish thee well.",
+ "layouts/ivar.html.erb" => "<%= yield %>, <%= @ivar %>"
)]
- def render_hello_world
+ def index
render :text => "hello david"
end
- def render_custom_code
+ def custom_code
render :text => "hello world", :status => 404
end
- def render_with_custom_code_as_string
+ def with_custom_code_as_string
render :text => "hello world", :status => "404 Not Found"
end
- def render_text_with_nil
+ def with_nil
render :text => nil
end
- def render_text_with_nil_and_status
+ def with_nil_and_status
render :text => nil, :status => 403
end
- def render_text_with_false
+ def with_false
render :text => false
end
- def render_text_with_layout
+ def with_layout_true
render :text => "hello world", :layout => true
end
- def render_text_with_layout_false
+ def with_layout_false
render :text => "hello world", :layout => false
end
- def render_text_with_layout_nil
+ def with_layout_nil
render :text => "hello world", :layout => nil
end
- def render_text_with_custom_layout
+ def with_custom_layout
render :text => "hello world", :layout => "greetings"
end
- end
-
- class TestSimpleTextRenderWithNoLayout < SimpleRouteCase
- describe "Rendering text from a action with default options renders the text with the layout"
- get "/happy_path/render_text_without_layouts/render_hello_world"
- assert_body "hello david"
- assert_status 200
+ def with_ivar_in_layout
+ @ivar = "hello world"
+ render :text => "hello world", :layout => "ivar"
+ end
end
-
+
class TestSimpleTextRenderWithLayout < SimpleRouteCase
describe "Rendering text from a action with default options renders the text without the layout"
- get "/happy_path/render_text_with_layouts/render_hello_world"
+ get "/render_text/with_layout"
assert_body "hello david"
assert_status 200
end
@@ -79,7 +84,7 @@ module HappyPath
class TestTextRenderWithStatus < SimpleRouteCase
describe "Rendering text, while also providing a custom status code"
- get "/happy_path/render_text_with_layouts/render_custom_code"
+ get "/render_text/with_layout/custom_code"
assert_body "hello world"
assert_status 404
end
@@ -87,7 +92,7 @@ module HappyPath
class TestTextRenderWithNil < SimpleRouteCase
describe "Rendering text with nil returns a single space character"
- get "/happy_path/render_text_with_layouts/render_text_with_nil"
+ get "/render_text/with_layout/with_nil"
assert_body " "
assert_status 200
end
@@ -95,7 +100,7 @@ module HappyPath
class TestTextRenderWithNilAndStatus < SimpleRouteCase
describe "Rendering text with nil and custom status code returns a single space character with the status"
- get "/happy_path/render_text_with_layouts/render_text_with_nil_and_status"
+ get "/render_text/with_layout/with_nil_and_status"
assert_body " "
assert_status 403
end
@@ -103,7 +108,7 @@ module HappyPath
class TestTextRenderWithFalse < SimpleRouteCase
describe "Rendering text with false returns the string 'false'"
- get "/happy_path/render_text_with_layouts/render_text_with_false"
+ get "/render_text/with_layout/with_false"
assert_body "false"
assert_status 200
end
@@ -111,7 +116,7 @@ module HappyPath
class TestTextRenderWithLayoutTrue < SimpleRouteCase
describe "Rendering text with :layout => true"
- get "/happy_path/render_text_with_layouts/render_text_with_layout"
+ get "/render_text/with_layout/with_layout_true"
assert_body "hello world, I'm here!"
assert_status 200
end
@@ -119,7 +124,7 @@ module HappyPath
class TestTextRenderWithCustomLayout < SimpleRouteCase
describe "Rendering text with :layout => 'greetings'"
- get "/happy_path/render_text_with_layouts/render_text_with_custom_layout"
+ get "/render_text/with_layout/with_custom_layout"
assert_body "hello world, I wish thee well."
assert_status 200
end
@@ -127,7 +132,7 @@ module HappyPath
class TestTextRenderWithLayoutFalse < SimpleRouteCase
describe "Rendering text with :layout => false"
- get "/happy_path/render_text_with_layouts/render_text_with_layout_false"
+ get "/render_text/with_layout/with_layout_false"
assert_body "hello world"
assert_status 200
end
@@ -135,10 +140,10 @@ module HappyPath
class TestTextRenderWithLayoutNil < SimpleRouteCase
describe "Rendering text with :layout => nil"
- get "/happy_path/render_text_with_layouts/render_text_with_layout_nil"
+ get "/render_text/with_layout/with_layout_nil"
assert_body "hello world"
assert_status 200
end
end
-ActionController::Base2.app_loaded! \ No newline at end of file
+ActionController::Base.app_loaded! \ 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 89c29d9af3..78662dc989 100644
--- a/actionpack/test/new_base/test_helper.rb
+++ b/actionpack/test/new_base/test_helper.rb
@@ -5,8 +5,7 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
require 'test/unit'
require 'active_support'
require 'active_support/test_case'
-require 'action_controller'
-require 'action_view/base'
+require 'action_view'
require 'fixture_template'
begin
@@ -24,35 +23,11 @@ require 'pp' # require 'pp' early to prevent hidden_methods from not picking up
require 'rubygems'
require 'rack/test'
-module ActionController
- class Base2 < AbstractBase
- include AbstractController::Callbacks
- include AbstractController::Helpers
- include AbstractController::Logger
-
- include ActionController::HideActions
- include ActionController::UrlFor
- include ActionController::Renderer
- include ActionController::Layouts
-
- def self.inherited(klass)
- ::ActionController::Base2.subclasses << klass.to_s
- super
- end
-
- def self.subclasses
- @subclasses ||= []
- end
-
- def self.app_loaded!
- @subclasses.each do |subclass|
- subclass.constantize._write_layout_method
- end
- end
-
- # append_view_path File.join(File.dirname(__FILE__), '..', 'fixtures')
-
- CORE_METHODS = self.public_instance_methods
+module Rails
+ def self.env
+ x = Object.new
+ def x.test?() true end
+ x
end
end
@@ -64,7 +39,7 @@ class Rack::TestCase < ActiveSupport::TestCase
ActionController::Base.session_options[:key] = "abc"
ActionController::Base.session_options[:secret] = ("*" * 30)
- controllers = ActionController::Base2.subclasses.map do |k|
+ controllers = ActionController::Base.subclasses.map do |k|
k.underscore.sub(/_controller$/, '')
end
@@ -91,7 +66,7 @@ class Rack::TestCase < ActiveSupport::TestCase
end
def assert_body(body)
- assert_equal [body], last_response.body
+ assert_equal body, Array.wrap(last_response.body).join
end
def self.assert_body(body)
@@ -132,7 +107,7 @@ class Rack::TestCase < ActiveSupport::TestCase
end
-class ::ApplicationController < ActionController::Base2
+class ::ApplicationController < ActionController::Base
end
class SimpleRouteCase < Rack::TestCase