Allow a custom dispatcher to be provided to routing.

This commit is contained in:
Xavier Shay 2013-07-07 14:34:46 -07:00
parent f26ae7d10f
commit 2992b1c04c
4 changed files with 17 additions and 19 deletions

@ -317,7 +317,7 @@ def define_url_helper(mod, route, name, opts, route_key, url_strategy)
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
@ -360,6 +360,7 @@ def initialize(config = DEFAULT_CONFIG)
@set = Journey::Routes.new
@router = Journey::Router.new @set
@formatter = Journey::Formatter.new @set
@dispatcher_class = Routing::RouteSet::Dispatcher
end
def relative_url_root
@ -418,7 +419,7 @@ def clear!
end
def dispatcher(defaults)
Routing::RouteSet::Dispatcher.new(defaults)
dispatcher_class.new(defaults)
end
module MountedHelpers

@ -149,14 +149,10 @@ def dispatch(controller, action, env)
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)

@ -19,6 +19,10 @@ def request_class
ActionDispatch::Request
end
def dispatcher_class
RouteSet::Dispatcher
end
def add_route(*args)
routes << args
end

@ -168,12 +168,10 @@ def test_session_singleton_resource
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 @@ def test_projects
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