diff options
Diffstat (limited to 'actionpack/test/controller')
25 files changed, 1517 insertions, 153 deletions
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 1a9f95e5e9..69b0eb5e3e 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -46,14 +46,8 @@ end class PageCachingTest < ActionController::TestCase def setup super - ActionController::Base.perform_caching = true - ActionController::Routing::Routes.draw do |map| - map.main '', :controller => 'posts', :format => nil - map.formatted_posts 'posts.:format', :controller => 'posts' - map.resources :posts - map.connect ':controller/:action/:id' - end + ActionController::Base.perform_caching = true @request = ActionController::TestRequest.new @request.host = 'hostname.com' @@ -74,10 +68,16 @@ class PageCachingTest < ActionController::TestCase end def test_page_caching_resources_saves_to_correct_path_with_extension_even_if_default_route - @params[:format] = 'rss' - assert_equal '/posts.rss', @rewriter.rewrite(@params) - @params[:format] = nil - assert_equal '/', @rewriter.rewrite(@params) + with_routing do |set| + set.draw do |map| + map.main '', :controller => 'posts', :format => nil + map.formatted_posts 'posts.:format', :controller => 'posts' + end + @params[:format] = 'rss' + assert_equal '/posts.rss', @rewriter.rewrite(@params) + @params[:format] = nil + assert_equal '/', @rewriter.rewrite(@params) + end end def test_should_cache_get_with_ok_status diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 0e4ca21143..508364d0b5 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -372,11 +372,8 @@ class IntegrationProcessTest < ActionController::IntegrationTest def with_test_route_set with_routing do |set| set.draw do |map| - map.with_options :controller => "IntegrationProcessTest::Integration" do |c| - c.connect "/:action" - end + map.connect "/:action", :controller => "integration_process_test/integration" end - reset! yield end end diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 93a815adae..a79648396c 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -527,12 +527,6 @@ class RespondWithControllerTest < ActionController::TestCase super ActionController::Base.use_accept_header = true @request.host = "www.example.com" - - ActionController::Routing::Routes.draw do |map| - map.resources :customers - map.resources :quiz_stores, :has_many => :customers - map.connect ":controller/:action/:id" - end end def teardown @@ -593,53 +587,59 @@ class RespondWithControllerTest < ActionController::TestCase end def test_using_resource_for_post_with_html - post :using_resource - assert_equal "text/html", @response.content_type - assert_equal 302, @response.status - assert_equal "http://www.example.com/customers/13", @response.location - assert @response.redirect? - - errors = { :name => :invalid } - Customer.any_instance.stubs(:errors).returns(errors) - post :using_resource - assert_equal "text/html", @response.content_type - assert_equal 200, @response.status - assert_equal "New world!\n", @response.body - assert_nil @response.location + with_test_route_set do + post :using_resource + assert_equal "text/html", @response.content_type + assert_equal 302, @response.status + assert_equal "http://www.example.com/customers/13", @response.location + assert @response.redirect? + + errors = { :name => :invalid } + Customer.any_instance.stubs(:errors).returns(errors) + post :using_resource + assert_equal "text/html", @response.content_type + assert_equal 200, @response.status + assert_equal "New world!\n", @response.body + assert_nil @response.location + end end def test_using_resource_for_post_with_xml - @request.accept = "application/xml" - - post :using_resource - assert_equal "application/xml", @response.content_type - assert_equal 201, @response.status - assert_equal "<name>david</name>", @response.body - assert_equal "http://www.example.com/customers/13", @response.location - - errors = { :name => :invalid } - Customer.any_instance.stubs(:errors).returns(errors) - post :using_resource - assert_equal "application/xml", @response.content_type - assert_equal 422, @response.status - assert_equal errors.to_xml, @response.body - assert_nil @response.location + with_test_route_set do + @request.accept = "application/xml" + + post :using_resource + assert_equal "application/xml", @response.content_type + assert_equal 201, @response.status + assert_equal "<name>david</name>", @response.body + assert_equal "http://www.example.com/customers/13", @response.location + + errors = { :name => :invalid } + Customer.any_instance.stubs(:errors).returns(errors) + post :using_resource + assert_equal "application/xml", @response.content_type + assert_equal 422, @response.status + assert_equal errors.to_xml, @response.body + assert_nil @response.location + end end def test_using_resource_for_put_with_html - put :using_resource - assert_equal "text/html", @response.content_type - assert_equal 302, @response.status - assert_equal "http://www.example.com/customers/13", @response.location - assert @response.redirect? - - errors = { :name => :invalid } - Customer.any_instance.stubs(:errors).returns(errors) - put :using_resource - assert_equal "text/html", @response.content_type - assert_equal 200, @response.status - assert_equal "Edit world!\n", @response.body - assert_nil @response.location + with_test_route_set do + put :using_resource + assert_equal "text/html", @response.content_type + assert_equal 302, @response.status + assert_equal "http://www.example.com/customers/13", @response.location + assert @response.redirect? + + errors = { :name => :invalid } + Customer.any_instance.stubs(:errors).returns(errors) + put :using_resource + assert_equal "text/html", @response.content_type + assert_equal 200, @response.status + assert_equal "Edit world!\n", @response.body + assert_nil @response.location + end end def test_using_resource_for_put_with_xml @@ -660,11 +660,13 @@ class RespondWithControllerTest < ActionController::TestCase end def test_using_resource_for_delete_with_html - Customer.any_instance.stubs(:destroyed?).returns(true) - delete :using_resource - assert_equal "text/html", @response.content_type - assert_equal 302, @response.status - assert_equal "http://www.example.com/customers", @response.location + with_test_route_set do + Customer.any_instance.stubs(:destroyed?).returns(true) + delete :using_resource + assert_equal "text/html", @response.content_type + assert_equal 302, @response.status + assert_equal "http://www.example.com/customers", @response.location + end end def test_using_resource_for_delete_with_xml @@ -685,21 +687,23 @@ class RespondWithControllerTest < ActionController::TestCase end def test_using_resource_with_parent_for_post - @request.accept = "application/xml" - - post :using_resource_with_parent - assert_equal "application/xml", @response.content_type - assert_equal 201, @response.status - assert_equal "<name>david</name>", @response.body - assert_equal "http://www.example.com/quiz_stores/11/customers/13", @response.location - - errors = { :name => :invalid } - Customer.any_instance.stubs(:errors).returns(errors) - post :using_resource - assert_equal "application/xml", @response.content_type - assert_equal 422, @response.status - assert_equal errors.to_xml, @response.body - assert_nil @response.location + with_test_route_set do + @request.accept = "application/xml" + + post :using_resource_with_parent + assert_equal "application/xml", @response.content_type + assert_equal 201, @response.status + assert_equal "<name>david</name>", @response.body + assert_equal "http://www.example.com/quiz_stores/11/customers/13", @response.location + + errors = { :name => :invalid } + Customer.any_instance.stubs(:errors).returns(errors) + post :using_resource + assert_equal "application/xml", @response.content_type + assert_equal 422, @response.status + assert_equal errors.to_xml, @response.body + assert_nil @response.location + end end def test_using_resource_with_collection @@ -773,6 +777,18 @@ class RespondWithControllerTest < ActionController::TestCase get :default_overwritten assert_equal 406, @response.status end + + private + def with_test_route_set + with_routing do |set| + set.draw do |map| + map.resources :customers + map.resources :quiz_stores, :has_many => :customers + map.connect ":controller/:action/:id" + end + yield + end + end end class AbstractPostController < ActionController::Base diff --git a/actionpack/test/controller/new_base/base_test.rb b/actionpack/test/controller/new_base/base_test.rb new file mode 100644 index 0000000000..1f9bf7f0fb --- /dev/null +++ b/actionpack/test/controller/new_base/base_test.rb @@ -0,0 +1,68 @@ +require 'abstract_unit' + +# Tests the controller dispatching happy path +module Dispatching + class SimpleController < ActionController::Base + def index + render :text => "success" + end + + def modify_response_body + self.response_body = "success" + end + + def modify_response_body_twice + ret = (self.response_body = "success") + self.response_body = "#{ret}!" + end + + def modify_response_headers + end + end + + class EmptyController < ActionController::Base ; end + + module Submodule + class ContainedEmptyController < ActionController::Base ; end + end + + class BaseTest < Rack::TestCase + # :api: plugin + test "simple dispatching" do + get "/dispatching/simple/index" + + assert_body "success" + assert_status 200 + assert_content_type "text/html; charset=utf-8" + end + + # :api: plugin + test "directly modifying response body" do + get "/dispatching/simple/modify_response_body" + + assert_body "success" + end + + # :api: plugin + test "directly modifying response body twice" do + get "/dispatching/simple/modify_response_body_twice" + + assert_body "success!" + end + + test "controller path" do + assert_equal 'dispatching/empty', EmptyController.controller_path + assert_equal EmptyController.controller_path, EmptyController.new.controller_path + end + + test "namespaced controller path" do + assert_equal 'dispatching/submodule/contained_empty', Submodule::ContainedEmptyController.controller_path + assert_equal Submodule::ContainedEmptyController.controller_path, Submodule::ContainedEmptyController.new.controller_path + end + + test "controller name" do + assert_equal 'empty', EmptyController.controller_name + assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name + end + end +end diff --git a/actionpack/test/controller/new_base/content_negotiation_test.rb b/actionpack/test/controller/new_base/content_negotiation_test.rb new file mode 100644 index 0000000000..7b38a82f51 --- /dev/null +++ b/actionpack/test/controller/new_base/content_negotiation_test.rb @@ -0,0 +1,18 @@ +require 'abstract_unit' + +module ContentNegotiation + + # This has no layout and it works + class BasicController < ActionController::Base + self.view_paths = [ActionView::FixtureResolver.new( + "content_negotiation/basic/hello.html.erb" => "Hello world <%= request.formats %>!" + )] + end + + class TestContentNegotiation < Rack::TestCase + test "A */* Accept header will return HTML" do + get "/content_negotiation/basic/hello", {}, "HTTP_ACCEPT" => "*/*" + assert_body "Hello world */*!" + end + end +end diff --git a/actionpack/test/controller/new_base/content_type_test.rb b/actionpack/test/controller/new_base/content_type_test.rb new file mode 100644 index 0000000000..0ff5552b08 --- /dev/null +++ b/actionpack/test/controller/new_base/content_type_test.rb @@ -0,0 +1,111 @@ +require 'abstract_unit' + +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 ImpliedController < ActionController::Base + # Template's mime type is used if no content_type is specified + + self.view_paths = [ActionView::FixtureResolver.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 CharsetController < 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 ExplicitContentTypeTest < Rack::TestCase + test "default response is HTML and UTF8" do + get "/content_type/base" + + assert_body "Hello world!" + assert_header "Content-Type", "text/html; charset=utf-8" + end + + test "setting the content type of the response directly on the response object" do + get "/content_type/base/set_on_response_obj" + + assert_body "Hello world!" + assert_header "Content-Type", "application/rss+xml; charset=utf-8" + end + + test "setting the content type of the response as an option to render" do + get "/content_type/base/set_on_render" + + assert_body "Hello world!" + assert_header "Content-Type", "application/rss+xml; charset=utf-8" + end + end + + class ImpliedContentTypeTest < Rack::TestCase + 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", "format" => "xml" + + 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", "format" => "xml" + + assert_header "Content-Type", "application/xml; charset=utf-8" + end + end + + class ExplicitCharsetTest < Rack::TestCase + test "setting the charset of the response directly on the response object" do + get "/content_type/charset/set_on_response_obj" + + assert_body "Hello world!" + assert_header "Content-Type", "text/html; charset=utf-16" + end + + test "setting the charset of the response as nil directly on the response object" do + get "/content_type/charset/set_as_nil_on_response_obj" + + assert_body "Hello world!" + assert_header "Content-Type", "text/html; charset=utf-8" + end + end +end diff --git a/actionpack/test/controller/new_base/etag_test.rb b/actionpack/test/controller/new_base/etag_test.rb new file mode 100644 index 0000000000..51bfb2278a --- /dev/null +++ b/actionpack/test/controller/new_base/etag_test.rb @@ -0,0 +1,46 @@ +require 'abstract_unit' + +module Etags + class BasicController < ActionController::Base + self.view_paths = [ActionView::FixtureResolver.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 => "etags" + end + end + + class EtagTest < Rack::TestCase + 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 + + private + + def etag_for(text) + %("#{Digest::MD5.hexdigest(text)}") + end + end +end diff --git a/actionpack/test/controller/new_base/metal_test.rb b/actionpack/test/controller/new_base/metal_test.rb new file mode 100644 index 0000000000..e1d46b906e --- /dev/null +++ b/actionpack/test/controller/new_base/metal_test.rb @@ -0,0 +1,43 @@ +require 'abstract_unit' + +module MetalTest + class MetalMiddleware < ActionController::Middleware + def call(env) + if env["PATH_INFO"] =~ /authed/ + app.call(env) + else + [401, headers, "Not authed!"] + end + end + end + + class Endpoint + def call(env) + [200, {}, "Hello World"] + end + end + + class TestMiddleware < ActiveSupport::TestCase + def setup + @app = Rack::Builder.new do + use MetalMiddleware + run Endpoint.new + end.to_app + end + + test "it can call the next app by using @app" do + env = Rack::MockRequest.env_for("/authed") + response = @app.call(env) + + assert_equal "Hello World", response[2] + end + + test "it can return a response using the normal AC::Metal techniques" do + env = Rack::MockRequest.env_for("/") + response = @app.call(env) + + assert_equal "Not authed!", response[2] + assert_equal 401, response[0] + end + end +end diff --git a/actionpack/test/controller/new_base/middleware_test.rb b/actionpack/test/controller/new_base/middleware_test.rb new file mode 100644 index 0000000000..ada0215b1a --- /dev/null +++ b/actionpack/test/controller/new_base/middleware_test.rb @@ -0,0 +1,77 @@ +require 'abstract_unit' + +module MiddlewareTest + class MyMiddleware + def initialize(app) + @app = app + end + + def call(env) + result = @app.call(env) + result[1]["Middleware-Test"] = "Success" + result[1]["Middleware-Order"] = "First" + result + end + end + + class ExclaimerMiddleware + def initialize(app) + @app = app + end + + def call(env) + result = @app.call(env) + result[1]["Middleware-Order"] << "!" + result + end + end + + class MyController < ActionController::Metal + use MyMiddleware + + middleware.insert_before MyMiddleware, ExclaimerMiddleware + + def index + self.response_body = "Hello World" + end + end + + class InheritedController < MyController + end + + module MiddlewareTests + extend ActiveSupport::Testing::Declarative + + test "middleware that is 'use'd is called as part of the Rack application" do + result = @app.call(env_for("/")) + assert_equal "Hello World", result[2] + assert_equal "Success", result[1]["Middleware-Test"] + end + + test "the middleware stack is exposed as 'middleware' in the controller" do + result = @app.call(env_for("/")) + assert_equal "First!", result[1]["Middleware-Order"] + end + end + + class TestMiddleware < ActiveSupport::TestCase + include MiddlewareTests + + def setup + @app = MyController.action(:index) + end + + def env_for(url) + Rack::MockRequest.env_for(url) + end + end + + class TestInheritedMiddleware < TestMiddleware + def setup + @app = InheritedController.action(:index) + end + + test "middleware inherits" do + end + end +end diff --git a/actionpack/test/controller/new_base/render_action_test.rb b/actionpack/test/controller/new_base/render_action_test.rb new file mode 100644 index 0000000000..ecd29c4530 --- /dev/null +++ b/actionpack/test/controller/new_base/render_action_test.rb @@ -0,0 +1,320 @@ +require 'abstract_unit' + +module RenderAction + # This has no layout and it works + class BasicController < ActionController::Base + self.view_paths = [ActionView::FixtureResolver.new( + "render_action/basic/hello_world.html.erb" => "Hello world!" + )] + + def hello_world + render :action => "hello_world" + end + + def hello_world_as_string + render "hello_world" + end + + def hello_world_as_string_with_options + render "hello_world", :status => 404 + end + + def hello_world_as_symbol + render :hello_world + end + + def hello_world_with_symbol + render :action => :hello_world + end + + def hello_world_with_layout + render :action => "hello_world", :layout => true + end + + def hello_world_with_layout_false + render :action => "hello_world", :layout => false + end + + def hello_world_with_layout_nil + render :action => "hello_world", :layout => nil + end + + def hello_world_with_custom_layout + render :action => "hello_world", :layout => "greetings" + end + + end + + class RenderActionTest < Rack::TestCase + test "rendering an action using :action => <String>" do + get "/render_action/basic/hello_world" + + assert_body "Hello world!" + assert_status 200 + end + + test "rendering an action using '<action>'" do + get "/render_action/basic/hello_world_as_string" + + assert_body "Hello world!" + assert_status 200 + end + + test "rendering an action using '<action>' and options" do + get "/render_action/basic/hello_world_as_string_with_options" + + assert_body "Hello world!" + assert_status 404 + end + + test "rendering an action using :action" do + get "/render_action/basic/hello_world_as_symbol" + + assert_body "Hello world!" + assert_status 200 + end + + test "rendering an action using :action => :hello_world" do + get "/render_action/basic/hello_world_with_symbol" + + assert_body "Hello world!" + assert_status 200 + end + end + + class RenderLayoutTest < Rack::TestCase + describe "Both <controller_path>.html.erb and application.html.erb are missing" + + test "rendering with layout => true" do + assert_raise(ArgumentError, /no default layout for RenderAction::BasicController in/) do + get "/render_action/basic/hello_world_with_layout", {}, "action_dispatch.show_exceptions" => false + end + end + + test "rendering with layout => false" do + get "/render_action/basic/hello_world_with_layout_false" + + assert_body "Hello world!" + assert_status 200 + end + + test "rendering with layout => :nil" do + get "/render_action/basic/hello_world_with_layout_nil" + + assert_body "Hello world!" + assert_status 200 + end + + test "rendering with layout => 'greetings'" do + assert_raise(ActionView::MissingTemplate) do + get "/render_action/basic/hello_world_with_custom_layout", {}, "action_dispatch.show_exceptions" => false + end + end + end +end + +module RenderActionWithApplicationLayout + # # ==== Render actions with layouts ==== + class BasicController < ::ApplicationController + # Set the view path to an application view structure with layouts + self.view_paths = self.view_paths = [ActionView::FixtureResolver.new( + "render_action_with_application_layout/basic/hello_world.html.erb" => "Hello World!", + "render_action_with_application_layout/basic/hello.html.builder" => "xml.p 'Omg'", + "layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI", + "layouts/greetings.html.erb" => "Greetings <%= yield %> Bai", + "layouts/builder.html.builder" => "xml.html do\n xml << yield\nend" + )] + + def hello_world + render :action => "hello_world" + end + + def hello_world_with_layout + render :action => "hello_world", :layout => true + end + + def hello_world_with_layout_false + render :action => "hello_world", :layout => false + end + + def hello_world_with_layout_nil + render :action => "hello_world", :layout => nil + end + + def hello_world_with_custom_layout + render :action => "hello_world", :layout => "greetings" + end + + def with_builder_and_layout + render :action => "hello", :layout => "builder" + end + end + + class LayoutTest < Rack::TestCase + describe "Only application.html.erb is present and <controller_path>.html.erb is missing" + + test "rendering implicit application.html.erb as layout" do + get "/render_action_with_application_layout/basic/hello_world" + + assert_body "OHAI Hello World! KTHXBAI" + assert_status 200 + end + + test "rendering with layout => true" do + get "/render_action_with_application_layout/basic/hello_world_with_layout" + + assert_body "OHAI Hello World! KTHXBAI" + assert_status 200 + end + + test "rendering with layout => false" do + get "/render_action_with_application_layout/basic/hello_world_with_layout_false" + + assert_body "Hello World!" + assert_status 200 + end + + test "rendering with layout => :nil" do + get "/render_action_with_application_layout/basic/hello_world_with_layout_nil" + + assert_body "Hello World!" + assert_status 200 + end + + test "rendering with layout => 'greetings'" do + get "/render_action_with_application_layout/basic/hello_world_with_custom_layout" + + assert_body "Greetings Hello World! Bai" + assert_status 200 + end + end + + class TestLayout < Rack::TestCase + testing BasicController + + test "builder works with layouts" do + get :with_builder_and_layout + assert_response "<html>\n<p>Omg</p>\n</html>\n" + end + end + +end + +module RenderActionWithControllerLayout + class BasicController < ActionController::Base + self.view_paths = self.view_paths = [ActionView::FixtureResolver.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" + )] + + def hello_world + render :action => "hello_world" + end + + def hello_world_with_layout + render :action => "hello_world", :layout => true + end + + def hello_world_with_layout_false + render :action => "hello_world", :layout => false + end + + def hello_world_with_layout_nil + render :action => "hello_world", :layout => nil + end + + def hello_world_with_custom_layout + render :action => "hello_world", :layout => "greetings" + end + end + + class ControllerLayoutTest < Rack::TestCase + describe "Only <controller_path>.html.erb is present and application.html.erb is missing" + + test "render hello_world and implicitly use <controller_path>.html.erb as a layout." do + get "/render_action_with_controller_layout/basic/hello_world" + + assert_body "With Controller Layout! Hello World! KTHXBAI" + assert_status 200 + end + + test "rendering with layout => true" do + get "/render_action_with_controller_layout/basic/hello_world_with_layout" + + assert_body "With Controller Layout! Hello World! KTHXBAI" + assert_status 200 + end + + test "rendering with layout => false" do + get "/render_action_with_controller_layout/basic/hello_world_with_layout_false" + + assert_body "Hello World!" + assert_status 200 + end + + test "rendering with layout => :nil" do + get "/render_action_with_controller_layout/basic/hello_world_with_layout_nil" + + assert_body "Hello World!" + assert_status 200 + end + end +end + +module RenderActionWithBothLayouts + class BasicController < ActionController::Base + self.view_paths = [ActionView::FixtureResolver.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" + })] + + def hello_world + render :action => "hello_world" + end + + def hello_world_with_layout + render :action => "hello_world", :layout => true + end + + def hello_world_with_layout_false + render :action => "hello_world", :layout => false + end + + def hello_world_with_layout_nil + render :action => "hello_world", :layout => nil + end + end + + class ControllerLayoutTest < Rack::TestCase + describe "Both <controller_path>.html.erb and application.html.erb are present" + + test "rendering implicitly use <controller_path>.html.erb over application.html.erb as a layout" do + get "/render_action_with_both_layouts/basic/hello_world" + + assert_body "With Controller Layout! Hello World! KTHXBAI" + assert_status 200 + end + + test "rendering with layout => true" do + get "/render_action_with_both_layouts/basic/hello_world_with_layout" + + assert_body "With Controller Layout! Hello World! KTHXBAI" + assert_status 200 + end + + test "rendering with layout => false" do + get "/render_action_with_both_layouts/basic/hello_world_with_layout_false" + + assert_body "Hello World!" + assert_status 200 + end + + test "rendering with layout => :nil" do + get "/render_action_with_both_layouts/basic/hello_world_with_layout_nil" + + assert_body "Hello World!" + assert_status 200 + end + end +end diff --git a/actionpack/test/controller/new_base/render_file_test.rb b/actionpack/test/controller/new_base/render_file_test.rb new file mode 100644 index 0000000000..8b2fdf8f96 --- /dev/null +++ b/actionpack/test/controller/new_base/render_file_test.rb @@ -0,0 +1,99 @@ +require 'abstract_unit' + +module RenderFile + class BasicController < ActionController::Base + self.view_paths = File.dirname(__FILE__) + + def index + render :file => File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world]) + end + + def with_instance_variables + @secret = 'in the sauce' + render :file => File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb') + end + + def without_file_key + render File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world]) + end + + def without_file_key_with_instance_variable + @secret = 'in the sauce' + render File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb') + end + + def relative_path + @secret = 'in the sauce' + render :file => '../../fixtures/test/render_file_with_ivar' + end + + def relative_path_with_dot + @secret = 'in the sauce' + render :file => '../../fixtures/test/dot.directory/render_file_with_ivar' + end + + def pathname + @secret = 'in the sauce' + render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar.erb]) + end + + def with_locals + path = File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_locals.erb') + render :file => path, :locals => {:secret => 'in the sauce'} + end + + def without_file_key_with_locals + path = FIXTURES.join('test/render_file_with_locals.erb').to_s + render path, :locals => {:secret => 'in the sauce'} + end + end + + class TestBasic < Rack::TestCase + testing RenderFile::BasicController + + test "rendering simple template" do + get :index + assert_response "Hello world!" + end + + test "rendering template with ivar" do + get :with_instance_variables + assert_response "The secret is in the sauce\n" + end + + test "rendering path without specifying the :file key" do + get :without_file_key + assert_response "Hello world!" + end + + test "rendering path without specifying the :file key with ivar" do + get :without_file_key_with_instance_variable + assert_response "The secret is in the sauce\n" + end + + test "rendering a relative path" do + get :relative_path + assert_response "The secret is in the sauce\n" + end + + test "rendering a relative path with dot" do + get :relative_path_with_dot + assert_response "The secret is in the sauce\n" + end + + test "rendering a Pathname" do + get :pathname + assert_response "The secret is in the sauce\n" + end + + test "rendering file with locals" do + get :with_locals + assert_response "The secret is in the sauce\n" + end + + test "rendering path without specifying the :file key with locals" do + get :without_file_key_with_locals + assert_response "The secret is in the sauce\n" + end + end +end diff --git a/actionpack/test/controller/new_base/render_implicit_action_test.rb b/actionpack/test/controller/new_base/render_implicit_action_test.rb new file mode 100644 index 0000000000..90cc7933ff --- /dev/null +++ b/actionpack/test/controller/new_base/render_implicit_action_test.rb @@ -0,0 +1,28 @@ +require 'abstract_unit' + +module RenderImplicitAction + class SimpleController < ::ApplicationController + self.view_paths = [ActionView::FixtureResolver.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 RenderImplicitActionTest < Rack::TestCase + test "render a simple action with new explicit call to render" do + get "/render_implicit_action/simple/hello_world" + + assert_body "Hello world!" + assert_status 200 + end + + test "render an action with a missing method and has special characters" do + get "/render_implicit_action/simple/hyphen-ated" + + assert_body "Hello hyphen-ated!" + assert_status 200 + end + end +end diff --git a/actionpack/test/controller/new_base/render_layout_test.rb b/actionpack/test/controller/new_base/render_layout_test.rb new file mode 100644 index 0000000000..6a9668b81a --- /dev/null +++ b/actionpack/test/controller/new_base/render_layout_test.rb @@ -0,0 +1,101 @@ +require 'abstract_unit' + +module ControllerLayouts + class ImplicitController < ::ApplicationController + self.view_paths = [ActionView::FixtureResolver.new( + "layouts/application.html.erb" => "OMG <%= yield %> KTHXBAI", + "layouts/override.html.erb" => "Override! <%= yield %>", + "basic.html.erb" => "Hello world!", + "controller_layouts/implicit/layout_false.html.erb" => "hai(layout_false.html.erb)" + )] + + def index + render :template => "basic" + end + + def override + render :template => "basic", :layout => "override" + end + + def layout_false + render :layout => false + end + + def builder_override + end + end + + class ImplicitNameController < ::ApplicationController + self.view_paths = [ActionView::FixtureResolver.new( + "layouts/controller_layouts/implicit_name.html.erb" => "OMGIMPLICIT <%= yield %> KTHXBAI", + "basic.html.erb" => "Hello world!" + )] + + def index + render :template => "basic" + end + end + + class RenderLayoutTest < Rack::TestCase + test "rendering a normal template, but using the implicit layout" do + get "/controller_layouts/implicit/index" + + assert_body "OMG Hello world! KTHXBAI" + assert_status 200 + end + + test "rendering a normal template, but using an implicit NAMED layout" do + get "/controller_layouts/implicit_name/index" + + assert_body "OMGIMPLICIT Hello world! KTHXBAI" + assert_status 200 + end + + test "overriding an implicit layout with render :layout option" do + get "/controller_layouts/implicit/override" + assert_body "Override! Hello world!" + end + + end + + class LayoutOptionsTest < Rack::TestCase + testing ControllerLayouts::ImplicitController + + test "rendering with :layout => false leaves out the implicit layout" do + get :layout_false + assert_response "hai(layout_false.html.erb)" + end + end + + class MismatchFormatController < ::ApplicationController + self.view_paths = [ActionView::FixtureResolver.new( + "layouts/application.html.erb" => "<html><%= yield %></html>", + "controller_layouts/mismatch_format/index.js.rjs" => "page[:test].omg", + "controller_layouts/mismatch_format/implicit.rjs" => "page[:test].omg" + )] + + def explicit + render :layout => "application" + end + end + + class MismatchFormatTest < Rack::TestCase + testing ControllerLayouts::MismatchFormatController + + test "if JS is selected, an HTML template is not also selected" do + get :index, "format" => "js" + assert_response "$(\"test\").omg();" + end + + test "if JS is implicitly selected, an HTML template is not also selected" do + get :implicit + assert_response "$(\"test\").omg();" + end + + test "if an HTML template is explicitly provides for a JS template, an error is raised" do + assert_raises ActionView::MissingTemplate do + get :explicit, {}, "action_dispatch.show_exceptions" => false + end + end + end +end diff --git a/actionpack/test/controller/new_base/render_partial_test.rb b/actionpack/test/controller/new_base/render_partial_test.rb new file mode 100644 index 0000000000..8fddcbcd57 --- /dev/null +++ b/actionpack/test/controller/new_base/render_partial_test.rb @@ -0,0 +1,27 @@ +require 'abstract_unit' + +module RenderPartial + + class BasicController < ActionController::Base + + self.view_paths = [ActionView::FixtureResolver.new( + "render_partial/basic/_basic.html.erb" => "OMG!", + "render_partial/basic/basic.html.erb" => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'basic' %><%= @test_unchanged %>" + )] + + def changing + @test_unchanged = 'hello' + render :action => "basic" + end + end + + class TestPartial < Rack::TestCase + testing BasicController + + test "rendering a partial in ActionView doesn't pull the ivars again from the controller" do + get :changing + assert_response("goodbyeOMG!goodbye") + end + end + +end diff --git a/actionpack/test/controller/new_base/render_rjs_test.rb b/actionpack/test/controller/new_base/render_rjs_test.rb new file mode 100644 index 0000000000..8c47b38ab6 --- /dev/null +++ b/actionpack/test/controller/new_base/render_rjs_test.rb @@ -0,0 +1,50 @@ +require 'abstract_unit' + +module RenderRjs + class BasicController < ActionController::Base + self.view_paths = [ActionView::FixtureResolver.new( + "render_rjs/basic/index.js.rjs" => "page[:customer].replace_html render(:partial => 'customer')", + "render_rjs/basic/index_html.js.rjs" => "page[:customer].replace_html :partial => 'customer'", + "render_rjs/basic/_customer.js.erb" => "JS Partial", + "render_rjs/basic/_customer.html.erb" => "HTML Partial", + "render_rjs/basic/index_locale.js.rjs" => "page[:customer].replace_html :partial => 'customer'", + "render_rjs/basic/_customer.da.html.erb" => "Danish HTML Partial", + "render_rjs/basic/_customer.da.js.erb" => "Danish JS Partial" + )] + + def index + render + end + + def index_locale + old_locale, I18n.locale = I18n.locale, :da + end + end + + class TestBasic < Rack::TestCase + testing BasicController + + def setup + @old_locale = I18n.locale + end + + def teardown + I18n.locale = @old_locale + end + + test "rendering a partial in an RJS template should pick the JS template over the HTML one" do + get :index, "format" => "js" + assert_response("$(\"customer\").update(\"JS Partial\");") + end + + test "replacing an element with a partial in an RJS template should pick the HTML template over the JS one" do + get :index_html, "format" => "js" + assert_response("$(\"customer\").update(\"HTML Partial\");") + end + + test "replacing an element with a partial in an RJS template with a locale should pick the localed HTML template" do + get :index_locale, "format" => "js" + assert_response("$(\"customer\").update(\"Danish HTML Partial\");") + end + end +end diff --git a/actionpack/test/controller/new_base/render_template_test.rb b/actionpack/test/controller/new_base/render_template_test.rb new file mode 100644 index 0000000000..c81b951c0d --- /dev/null +++ b/actionpack/test/controller/new_base/render_template_test.rb @@ -0,0 +1,170 @@ +require 'abstract_unit' + +module RenderTemplate + class WithoutLayoutController < ActionController::Base + + self.view_paths = [ActionView::FixtureResolver.new( + "test/basic.html.erb" => "Hello from basic.html.erb", + "shared.html.erb" => "Elastica", + "locals.html.erb" => "The secret is <%= secret %>", + "xml_template.xml.builder" => "xml.html do\n xml.p 'Hello'\nend" + )] + + def index + render :template => "test/basic" + end + + def index_without_key + render "test/basic" + end + + def in_top_directory + render :template => 'shared' + end + + def in_top_directory_with_slash + render :template => '/shared' + end + + def in_top_directory_with_slash_without_key + render '/shared' + end + + def with_locals + render :template => "locals", :locals => { :secret => 'area51' } + end + + def builder_template + render :template => "xml_template" + end + end + + class TestWithoutLayout < Rack::TestCase + testing RenderTemplate::WithoutLayoutController + + test "rendering a normal template with full path without layout" do + get :index + assert_response "Hello from basic.html.erb" + end + + test "rendering a normal template with full path without layout without key" do + get :index_without_key + assert_response "Hello from basic.html.erb" + end + + test "rendering a template not in a subdirectory" do + get :in_top_directory + assert_response "Elastica" + end + + test "rendering a template not in a subdirectory with a leading slash" do + get :in_top_directory_with_slash + assert_response "Elastica" + end + + test "rendering a template not in a subdirectory with a leading slash without key" do + get :in_top_directory_with_slash_without_key + assert_response "Elastica" + end + + test "rendering a template with local variables" do + get :with_locals + assert_response "The secret is area51" + end + + test "rendering a builder template" do + get :builder_template, "format" => "xml" + assert_response "<html>\n <p>Hello</p>\n</html>\n" + end + end + + class WithLayoutController < ::ApplicationController + self.view_paths = [ActionView::FixtureResolver.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 index + render :template => "test/basic" + end + + def with_layout + render :template => "test/basic", :layout => true + end + + def with_layout_false + render :template => "test/basic", :layout => false + end + + def with_layout_nil + render :template => "test/basic", :layout => nil + end + + def with_custom_layout + render :template => "test/basic", :layout => "greetings" + end + end + + class TestWithLayout < Rack::TestCase + describe "Rendering with :template using implicit or explicit layout" + + test "rendering with implicit layout" do + get "/render_template/with_layout" + + assert_body "Hello from basic.html.erb, I'm here!" + assert_status 200 + end + + test "rendering with layout => :true" do + get "/render_template/with_layout/with_layout" + + assert_body "Hello from basic.html.erb, I'm here!" + assert_status 200 + end + + test "rendering with layout => :false" do + get "/render_template/with_layout/with_layout_false" + + assert_body "Hello from basic.html.erb" + assert_status 200 + end + + test "rendering with layout => :nil" do + get "/render_template/with_layout/with_layout_nil" + + assert_body "Hello from basic.html.erb" + assert_status 200 + end + + test "rendering layout => 'greetings'" do + get "/render_template/with_layout/with_custom_layout" + + assert_body "Hello from basic.html.erb, I wish thee well." + assert_status 200 + end + end + + module Compatibility + class WithoutLayoutController < ActionController::Base + self.view_paths = [ActionView::FixtureResolver.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 < Rack::TestCase + test "rendering a normal template with full path starting with a leading slash" do + get "/render_template/compatibility/without_layout/with_forward_slash" + + assert_body "Hello from basic.html.erb" + assert_status 200 + end + end + end +end diff --git a/actionpack/test/controller/new_base/render_test.rb b/actionpack/test/controller/new_base/render_test.rb new file mode 100644 index 0000000000..d985d9f9ad --- /dev/null +++ b/actionpack/test/controller/new_base/render_test.rb @@ -0,0 +1,85 @@ +require 'abstract_unit' + +module Render + class BlankRenderController < ActionController::Base + self.view_paths = [ActionView::FixtureResolver.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 DoubleRenderController < ActionController::Base + def index + render :text => "hello" + render :text => "world" + end + end + + class RenderTest < Rack::TestCase + test "render with blank" do + get "/render/blank_render" + + assert_body "Hello world!" + assert_status 200 + end + + test "rendering more than once raises an exception" do + assert_raises(AbstractController::DoubleRenderError) do + get "/render/double_render", {}, "action_dispatch.show_exceptions" => false + end + end + end + + class TestOnlyRenderPublicActions < Rack::TestCase + 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", {}, "action_dispatch.show_exceptions" => false + end + end + + test "raises an exception when a private method is called" do + assert_raises(AbstractController::ActionNotFound) do + get "/render/blank_render/secretz", {}, "action_dispatch.show_exceptions" => false + end + end + end + + class TestVariousObjectsAvailableInView < Rack::TestCase + 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 diff --git a/actionpack/test/controller/new_base/render_text_test.rb b/actionpack/test/controller/new_base/render_text_test.rb new file mode 100644 index 0000000000..0e6f51c998 --- /dev/null +++ b/actionpack/test/controller/new_base/render_text_test.rb @@ -0,0 +1,137 @@ +require 'abstract_unit' + +module RenderText + class SimpleController < ActionController::Base + self.view_paths = [ActionView::FixtureResolver.new] + + def index + render :text => "hello david" + end + end + + class WithLayoutController < ::ApplicationController + self.view_paths = [ActionView::FixtureResolver.new( + "layouts/application.html.erb" => "<%= yield %>, I'm here!", + "layouts/greetings.html.erb" => "<%= yield %>, I wish thee well.", + "layouts/ivar.html.erb" => "<%= yield %>, <%= @ivar %>" + )] + + def index + render :text => "hello david" + end + + def custom_code + render :text => "hello world", :status => 404 + end + + def with_custom_code_as_string + render :text => "hello world", :status => "404 Not Found" + end + + def with_nil + render :text => nil + end + + def with_nil_and_status + render :text => nil, :status => 403 + end + + def with_false + render :text => false + end + + def with_layout_true + render :text => "hello world", :layout => true + end + + def with_layout_false + render :text => "hello world", :layout => false + end + + def with_layout_nil + render :text => "hello world", :layout => nil + end + + def with_custom_layout + render :text => "hello world", :layout => "greetings" + end + + def with_ivar_in_layout + @ivar = "hello world" + render :text => "hello world", :layout => "ivar" + end + end + + class RenderTextTest < Rack::TestCase + describe "Rendering text using render :text" + + test "rendering text from a action with default options renders the text with the layout" do + get "/render_text/simple" + assert_body "hello david" + assert_status 200 + end + + test "rendering text from a action with default options renders the text without the layout" do + get "/render_text/with_layout" + + assert_body "hello david" + assert_status 200 + end + + test "rendering text, while also providing a custom status code" do + get "/render_text/with_layout/custom_code" + + assert_body "hello world" + assert_status 404 + end + + test "rendering text with nil returns an empty body padded for Safari" do + get "/render_text/with_layout/with_nil" + + assert_body " " + assert_status 200 + end + + test "Rendering text with nil and custom status code returns an empty body padded for Safari and the status" do + get "/render_text/with_layout/with_nil_and_status" + + assert_body " " + assert_status 403 + end + + test "rendering text with false returns the string 'false'" do + get "/render_text/with_layout/with_false" + + assert_body "false" + assert_status 200 + end + + test "rendering text with :layout => true" do + get "/render_text/with_layout/with_layout_true" + + assert_body "hello world, I'm here!" + assert_status 200 + end + + test "rendering text with :layout => 'greetings'" do + get "/render_text/with_layout/with_custom_layout" + + assert_body "hello world, I wish thee well." + assert_status 200 + end + + test "rendering text with :layout => false" do + get "/render_text/with_layout/with_layout_false" + + assert_body "hello world" + assert_status 200 + end + + test "rendering text with :layout => nil" do + get "/render_text/with_layout/with_layout_nil" + + assert_body "hello world" + assert_status 200 + end + end +end diff --git a/actionpack/test/controller/new_base/render_xml_test.rb b/actionpack/test/controller/new_base/render_xml_test.rb new file mode 100644 index 0000000000..d044738a78 --- /dev/null +++ b/actionpack/test/controller/new_base/render_xml_test.rb @@ -0,0 +1,11 @@ +require 'abstract_unit' + +module RenderXml + + # This has no layout and it works + class BasicController < ActionController::Base + self.view_paths = [ActionView::FixtureResolver.new( + "render_xml/basic/with_render_erb" => "Hello world!" + )] + end +end diff --git a/actionpack/test/controller/output_escaping_test.rb b/actionpack/test/controller/output_escaping_test.rb new file mode 100644 index 0000000000..7332f3f1e3 --- /dev/null +++ b/actionpack/test/controller/output_escaping_test.rb @@ -0,0 +1,19 @@ +require 'abstract_unit' + +class OutputEscapingTest < ActiveSupport::TestCase + + test "escape_html shouldn't die when passed nil" do + assert ERB::Util.h(nil).blank? + end + + test "escapeHTML should escape strings" do + assert_equal "<>"", ERB::Util.h("<>\"") + end + + test "escapeHTML shouldn't touch explicitly safe strings" do + # TODO this seems easier to compose and reason about, but + # this should be verified + assert_equal "<", ERB::Util.h("<".html_safe!) + end + +end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index abcc8bf384..2db524ca4b 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1050,7 +1050,7 @@ class RenderTest < ActionController::TestCase def test_action_talk_to_layout get :action_talk_to_layout - assert_equal "<title>Talking to the layout</title>\nAction was here!", @response.body + assert_equal "<title>Talking to the layout</title>\n\nAction was here!", @response.body end # :addressed: diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 6ad708bba1..689359166f 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -347,7 +347,6 @@ class RescueTest < ActionController::IntegrationTest map.connect 'invalid', :controller => "rescue_test/test", :action => 'invalid' map.connect 'b00m', :controller => "rescue_test/test", :action => 'b00m' end - reset! yield end end diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 1aabf71cad..edf243337f 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -669,21 +669,13 @@ class LegacyRouteSetTests < Test::Unit::TestCase %w(GET POST PUT DELETE).each do |request_method| define_method("test_request_method_recognized_with_#{request_method}") do - begin - Object.const_set(:BooksController, Class.new(ActionController::Base)) - - setup_request_method_routes_for(request_method) - - assert_nothing_raised { rs.recognize(@request) } - assert_equal request_method.downcase, @request.path_parameters[:action] - ensure - Object.send(:remove_const, :BooksController) rescue nil - end + setup_request_method_routes_for(request_method) + assert_nothing_raised { rs.recognize(@request) } + assert_equal request_method.downcase, @request.path_parameters[:action] end end def test_recognize_array_of_methods - Object.const_set(:BooksController, Class.new(ActionController::Base)) rs.draw do |r| r.connect '/match', :controller => 'books', :action => 'get_or_post', :conditions => { :method => [:get, :post] } r.connect '/match', :controller => 'books', :action => 'not_get_or_post' @@ -701,13 +693,9 @@ class LegacyRouteSetTests < Test::Unit::TestCase @request.request_uri = "/match" assert_nothing_raised { rs.recognize(@request) } assert_equal 'not_get_or_post', @request.path_parameters[:action] - ensure - Object.send(:remove_const, :BooksController) rescue nil end def test_subpath_recognized - Object.const_set(:SubpathBooksController, Class.new(ActionController::Base)) - rs.draw do |r| r.connect '/books/:id/edit', :controller => 'subpath_books', :action => 'edit' r.connect '/items/:id/:action', :controller => 'subpath_books' @@ -730,13 +718,9 @@ class LegacyRouteSetTests < Test::Unit::TestCase hash = rs.recognize_path "/posts/7" assert_not_nil hash assert_equal %w(subpath_books show 7), [hash[:controller], hash[:action], hash[:id]] - ensure - Object.send(:remove_const, :SubpathBooksController) rescue nil end def test_subpath_generated - Object.const_set(:SubpathBooksController, Class.new(ActionController::Base)) - rs.draw do |r| r.connect '/books/:id/edit', :controller => 'subpath_books', :action => 'edit' r.connect '/items/:id/:action', :controller => 'subpath_books' @@ -746,8 +730,6 @@ class LegacyRouteSetTests < Test::Unit::TestCase assert_equal "/books/7/edit", rs.generate(:controller => "subpath_books", :id => 7, :action => "edit") assert_equal "/items/15/complete", rs.generate(:controller => "subpath_books", :id => 15, :action => "complete") assert_equal "/posts/new/preview", rs.generate(:controller => "subpath_books", :action => "preview") - ensure - Object.send(:remove_const, :SubpathBooksController) rescue nil end def test_failed_requirements_raises_exception_with_violated_requirements @@ -1122,8 +1104,6 @@ class RouteSetTest < ActiveSupport::TestCase end def test_recognize_with_conditions - Object.const_set(:PeopleController, Class.new) - set.draw do |map| map.with_options(:controller => "people") do |people| people.people "/people", :action => "index", :conditions => { :method => :get } @@ -1183,14 +1163,9 @@ class RouteSetTest < ActiveSupport::TestCase assert_equal [:get, :put, :delete], e.allowed_methods end request.recycle! - - ensure - Object.send(:remove_const, :PeopleController) end def test_recognize_with_alias_in_conditions - Object.const_set(:PeopleController, Class.new) - set.draw do |map| map.people "/people", :controller => 'people', :action => "index", :conditions => { :method => :get } @@ -1208,13 +1183,9 @@ class RouteSetTest < ActiveSupport::TestCase assert_nothing_raised { set.recognize(request) } assert_equal("people", request.path_parameters[:controller]) assert_equal("index", request.path_parameters[:action]) - ensure - Object.send(:remove_const, :PeopleController) end def test_typo_recognition - Object.const_set(:ArticlesController, Class.new) - set.draw do |map| map.connect 'articles/:year/:month/:day/:title', :controller => 'articles', :action => 'permalink', @@ -1229,9 +1200,6 @@ class RouteSetTest < ActiveSupport::TestCase assert_equal("11", request.path_parameters[:month]) assert_equal("05", request.path_parameters[:day]) assert_equal("a-very-interesting-article", request.path_parameters[:title]) - - ensure - Object.send(:remove_const, :ArticlesController) end def test_routing_traversal_does_not_load_extra_classes @@ -1248,8 +1216,6 @@ class RouteSetTest < ActiveSupport::TestCase end def test_recognize_with_conditions_and_format - Object.const_set(:PeopleController, Class.new) - set.draw do |map| map.with_options(:controller => "people") do |people| people.person "/people/:id", :action => "show", :conditions => { :method => :get } @@ -1276,8 +1242,6 @@ class RouteSetTest < ActiveSupport::TestCase assert_equal("show", request.path_parameters[:action]) assert_equal("5", request.path_parameters[:id]) assert_equal("png", request.path_parameters[:_format]) - ensure - Object.send(:remove_const, :PeopleController) end def test_generate_with_default_action @@ -1291,8 +1255,6 @@ class RouteSetTest < ActiveSupport::TestCase end def test_root_map - Object.const_set(:PeopleController, Class.new) - set.draw { |map| map.root :controller => "people" } request.path = "" @@ -1300,13 +1262,9 @@ class RouteSetTest < ActiveSupport::TestCase assert_nothing_raised { set.recognize(request) } assert_equal("people", request.path_parameters[:controller]) assert_equal("index", request.path_parameters[:action]) - ensure - Object.send(:remove_const, :PeopleController) end def test_namespace - Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) }) - set.draw do |map| map.namespace 'api' do |api| @@ -1320,13 +1278,9 @@ class RouteSetTest < ActiveSupport::TestCase assert_nothing_raised { set.recognize(request) } assert_equal("api/products", request.path_parameters[:controller]) assert_equal("inventory", request.path_parameters[:action]) - ensure - Object.send(:remove_const, :Api) end def test_namespaced_root_map - Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) }) - set.draw do |map| map.namespace 'api' do |api| @@ -1340,13 +1294,9 @@ class RouteSetTest < ActiveSupport::TestCase assert_nothing_raised { set.recognize(request) } assert_equal("api/products", request.path_parameters[:controller]) assert_equal("index", request.path_parameters[:action]) - ensure - Object.send(:remove_const, :Api) end def test_namespace_with_path_prefix - Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) }) - set.draw do |map| map.namespace 'api', :path_prefix => 'prefix' do |api| api.route 'inventory', :controller => "products", :action => 'inventory' @@ -1358,13 +1308,9 @@ class RouteSetTest < ActiveSupport::TestCase assert_nothing_raised { set.recognize(request) } assert_equal("api/products", request.path_parameters[:controller]) assert_equal("inventory", request.path_parameters[:action]) - ensure - Object.send(:remove_const, :Api) end def test_namespace_with_blank_path_prefix - Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) }) - set.draw do |map| map.namespace 'api', :path_prefix => '' do |api| api.route 'inventory', :controller => "products", :action => 'inventory' @@ -1376,8 +1322,6 @@ class RouteSetTest < ActiveSupport::TestCase assert_nothing_raised { set.recognize(request) } assert_equal("api/products", request.path_parameters[:controller]) assert_equal("inventory", request.path_parameters[:action]) - ensure - Object.send(:remove_const, :Api) end def test_generate_changes_controller_module diff --git a/actionpack/test/controller/verification_test.rb b/actionpack/test/controller/verification_test.rb index ee558f3465..1a9eb65f29 100644 --- a/actionpack/test/controller/verification_test.rb +++ b/actionpack/test/controller/verification_test.rb @@ -111,13 +111,6 @@ class VerificationTest < ActionController::TestCase tests TestController - setup do - ActionController::Routing::Routes.draw do |map| - map.foo '/foo', :controller => 'test', :action => 'foo' - map.connect ":controller/:action/:id" - end - end - def test_using_symbol_back_with_no_referrer assert_raise(ActionController::RedirectBackError) { get :guarded_with_back } end @@ -130,8 +123,14 @@ class VerificationTest < ActionController::TestCase def test_no_deprecation_warning_for_named_route assert_not_deprecated do - get :guarded_one_for_named_route_test, :two => "not one" - assert_redirected_to '/foo' + with_routing do |set| + set.draw do |map| + map.foo '/foo', :controller => 'test', :action => 'foo' + map.connect ":controller/:action/:id" + end + get :guarded_one_for_named_route_test, :two => "not one" + assert_redirected_to '/foo' + end end end diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb index c04d20fbad..0514c098bf 100644 --- a/actionpack/test/controller/webservice_test.rb +++ b/actionpack/test/controller/webservice_test.rb @@ -259,7 +259,6 @@ class WebServiceTest < ActionController::IntegrationTest c.connect "/", :action => "assign_parameters" end end - reset! yield end end |