diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-08-08 12:22:21 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-08-08 12:22:21 -0300 |
commit | d919fd88ecbf79c969cf1896cb293345e43efb6a (patch) | |
tree | 66680a823c5c925e60a7e55cf293967727f674a2 /actionpack | |
parent | 12f08acbacf823041dae27afd1a1a1458bb1e3fa (diff) | |
parent | 2992b1c04c555c6483245257eab16026dd0fd889 (diff) | |
download | rails-d919fd88ecbf79c969cf1896cb293345e43efb6a.tar.gz rails-d919fd88ecbf79c969cf1896cb293345e43efb6a.tar.bz2 rails-d919fd88ecbf79c969cf1896cb293345e43efb6a.zip |
Merge pull request #11352 from xaviershay/dispatcher-api
Allow a custom dispatcher to be provided to routing.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 13 | ||||
-rw-r--r-- | actionpack/test/abstract_unit.rb | 12 | ||||
-rw-r--r-- | actionpack/test/dispatch/mapper_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 15 |
4 files changed, 23 insertions, 21 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index c9775a40b7..a8fb5aade3 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -62,13 +62,17 @@ module ActionDispatch raise ActionController::RoutingError, e.message, e.backtrace if default_controller end - private + protected + + attr_reader :controller_class_names def controller_reference(controller_param) - const_name = @controller_class_names[controller_param] ||= "#{controller_param.camelize}Controller" + const_name = controller_class_names[controller_param] ||= "#{controller_param.camelize}Controller" ActiveSupport::Dependencies.constantize(const_name) end + private + def dispatch(controller, action, req) controller.action(action).call(req.env) end @@ -313,7 +317,7 @@ module ActionDispatch attr_accessor :formatter, :set, :named_routes, :default_scope, :router attr_accessor :disable_clear_and_finalize, :resources_path_names - attr_accessor :default_url_options + attr_accessor :default_url_options, :dispatcher_class attr_reader :env_key alias :routes :set @@ -356,6 +360,7 @@ module ActionDispatch @set = Journey::Routes.new @router = Journey::Router.new @set @formatter = Journey::Formatter.new @set + @dispatcher_class = Routing::RouteSet::Dispatcher end def relative_url_root @@ -414,7 +419,7 @@ module ActionDispatch end def dispatcher(defaults) - Routing::RouteSet::Dispatcher.new(defaults) + dispatcher_class.new(defaults) end module MountedHelpers diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 09d55133e9..60e2cea8a2 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -130,14 +130,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 |