aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorXavier Shay <xavier@rhnh.net>2013-07-07 14:34:46 -0700
committerXavier Shay <xavier@rhnh.net>2015-08-07 20:06:24 -0700
commit2992b1c04c555c6483245257eab16026dd0fd889 (patch)
tree7b42732c971e8d0e457789f6dc9f7ef58938beee /actionpack/test
parentf26ae7d10f9b890a9ac5de70f0be4a9cf9149233 (diff)
downloadrails-2992b1c04c555c6483245257eab16026dd0fd889.tar.gz
rails-2992b1c04c555c6483245257eab16026dd0fd889.tar.bz2
rails-2992b1c04c555c6483245257eab16026dd0fd889.zip
Allow a custom dispatcher to be provided to routing.
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/abstract_unit.rb12
-rw-r--r--actionpack/test/dispatch/mapper_test.rb4
-rw-r--r--actionpack/test/dispatch/routing_test.rb15
3 files changed, 14 insertions, 17 deletions
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 771df5a0b2..5a49fb3cb8 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -149,14 +149,10 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
end
end
- def self.stub_controllers
- old_dispatcher = ActionDispatch::Routing::RouteSet::Dispatcher
- ActionDispatch::Routing::RouteSet.module_eval { remove_const :Dispatcher }
- ActionDispatch::Routing::RouteSet.module_eval { const_set :Dispatcher, StubDispatcher }
- yield ActionDispatch::Routing::RouteSet.new
- ensure
- ActionDispatch::Routing::RouteSet.module_eval { remove_const :Dispatcher }
- ActionDispatch::Routing::RouteSet.module_eval { const_set :Dispatcher, old_dispatcher }
+ def self.stub_controllers(config = nil)
+ route_set = ActionDispatch::Routing::RouteSet.new(*[config].compact)
+ route_set.dispatcher_class = StubDispatcher
+ yield route_set
end
def with_routing(&block)
diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb
index 889f9a4736..aed1d914f9 100644
--- a/actionpack/test/dispatch/mapper_test.rb
+++ b/actionpack/test/dispatch/mapper_test.rb
@@ -19,6 +19,10 @@ module ActionDispatch
ActionDispatch::Request
end
+ def dispatcher_class
+ RouteSet::Dispatcher
+ end
+
def add_route(*args)
routes << args
end
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index b18a9ab647..280b258da6 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -168,12 +168,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
def test_session_singleton_resource_for_api_app
- self.class.stub_controllers do |_|
- config = ActionDispatch::Routing::RouteSet::Config.new
- config.api_only = true
-
- routes = ActionDispatch::Routing::RouteSet.new(config)
+ config = ActionDispatch::Routing::RouteSet::Config.new
+ config.api_only = true
+ self.class.stub_controllers(config) do |routes|
routes.draw do
resource :session do
get :create
@@ -550,11 +548,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
def test_projects_for_api_app
- self.class.stub_controllers do |_|
- config = ActionDispatch::Routing::RouteSet::Config.new
- config.api_only = true
+ config = ActionDispatch::Routing::RouteSet::Config.new
+ config.api_only = true
- routes = ActionDispatch::Routing::RouteSet.new(config)
+ self.class.stub_controllers(config) do |routes|
routes.draw do
resources :projects, controller: :project
end