1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use ActionDispatch::Routing everywhere

This commit is contained in:
Martin Schürrer 2010-02-21 17:21:25 +01:00 committed by Yehuda Katz
parent 4cdfe98d92
commit 6bc24d40d5
24 changed files with 64 additions and 59 deletions

View file

@ -61,7 +61,7 @@ class ActionMailerUrlTest < Test::Unit::TestCase
def test_signed_up_with_url
TestMailer.delivery_method = :test
ActionController::Routing::Routes.draw do |map|
ActionDispatch::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
map.welcome 'welcome', :controller=>"foo", :action=>"bar"
end

View file

@ -1,5 +1,4 @@
ActionController::AbstractRequest = ActionController::Request = ActionDispatch::Request
ActionController::AbstractResponse = ActionController::Response = ActionDispatch::Response
ActionController::Routing = ActionDispatch::Routing
ActionController::Routing::Routes = ActionDispatch::Routing::RouteSet.new
ActionController::UrlWriter = ActionController::UrlFor

View file

@ -20,8 +20,8 @@ module ActionController
class << self
delegate :default_charset=, :to => "ActionDispatch::Response"
delegate :resources_path_names, :to => "ActionController::Routing::Routes"
delegate :resources_path_names=, :to => "ActionController::Routing::Routes"
delegate :resources_path_names, :to => "ActionDispatch::Routing::Routes"
delegate :resources_path_names=, :to => "ActionDispatch::Routing::Routes"
end
# cattr_reader :protected_instance_variables

View file

@ -6,7 +6,7 @@ module ActionController
# is also possible: an URL can be generated from one of your routing definitions.
# URL generation functionality is centralized in this module.
#
# See ActionController::Routing and ActionController::Resources for general
# See ActionDispatch::Routing and ActionController::Resources for general
# information about routing and routes.rb.
#
# <b>Tip:</b> If you need to generate URLs from your models or some other place,
@ -87,7 +87,7 @@ module ActionController
extend ActiveSupport::Concern
included do
ActionController::Routing::Routes.install_helpers(self)
ActionDispatch::Routing::Routes.install_helpers(self)
# Including in a class uses an inheritable hash. Modules get a plain hash.
if respond_to?(:class_attribute)

View file

@ -19,7 +19,7 @@ module ActionController
def assign_parameters(controller_path, action, parameters = {})
parameters = parameters.symbolize_keys.merge(:controller => controller_path, :action => action)
extra_keys = ActionController::Routing::Routes.extra_keys(parameters)
extra_keys = ActionDispatch::Routing::Routes.extra_keys(parameters)
non_path_parameters = get? ? query_parameters : request_parameters
parameters.each do |key, value|
if value.is_a? Fixnum

View file

@ -204,6 +204,7 @@ module ActionDispatch
autoload :DeprecatedMapper, 'action_dispatch/routing/deprecated_mapper'
autoload :Mapper, 'action_dispatch/routing/mapper'
autoload :Route, 'action_dispatch/routing/route'
autoload :Routes, 'action_dispatch/routing/routes'
autoload :RouteSet, 'action_dispatch/routing/route_set'
SEPARATORS = %w( / . ? )

View file

@ -0,0 +1,5 @@
# A singleton that stores the current route set
ActionDispatch::Routing::Routes = ActionDispatch::Routing::RouteSet.new
# To preserve compatibility with pre-3.0 Rails action_controller/deprecated.rb
# defines ActionDispatch::Routing::Routes as an alias

View file

@ -80,7 +80,7 @@ module ActionDispatch
expected_path = "/#{expected_path}" unless expected_path[0] == ?/
# Load routes.rb if it hasn't been loaded.
generated_path, extra_keys = ActionController::Routing::Routes.generate_extras(options, defaults)
generated_path, extra_keys = ActionDispatch::Routing::Routes.generate_extras(options, defaults)
found_extras = options.reject {|k, v| ! extra_keys.include? k}
msg = build_message(message, "found extras <?>, not <?>", found_extras, extras)
@ -125,7 +125,7 @@ module ActionDispatch
end
# A helper to make it easier to test different route configurations.
# This method temporarily replaces ActionController::Routing::Routes
# This method temporarily replaces ActionDispatch::Routing::Routes
# with a new RouteSet instance.
#
# The new instance is yielded to the passed block. Typically the block
@ -142,22 +142,22 @@ module ActionDispatch
# end
#
def with_routing
real_routes = ActionController::Routing::Routes
ActionController::Routing.module_eval { remove_const :Routes }
real_routes = ActionDispatch::Routing::Routes
ActionDispatch::Routing.module_eval { remove_const :Routes }
temporary_routes = ActionController::Routing::RouteSet.new
ActionController::Routing.module_eval { const_set :Routes, temporary_routes }
temporary_routes = ActionDispatch::Routing::RouteSet.new
ActionDispatch::Routing.module_eval { const_set :Routes, temporary_routes }
yield temporary_routes
ensure
if ActionController::Routing.const_defined? :Routes
ActionController::Routing.module_eval { remove_const :Routes }
if ActionDispatch::Routing.const_defined? :Routes
ActionDispatch::Routing.module_eval { remove_const :Routes }
end
ActionController::Routing.const_set(:Routes, real_routes) if real_routes
ActionDispatch::Routing.const_set(:Routes, real_routes) if real_routes
end
def method_missing(selector, *args, &block)
if @controller && ActionController::Routing::Routes.named_routes.helpers.include?(selector)
if @controller && ActionDispatch::Routing::Routes.named_routes.helpers.include?(selector)
@controller.send(selector, *args, &block)
else
super
@ -174,7 +174,7 @@ module ActionDispatch
request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method
request.path = path
params = ActionController::Routing::Routes.recognize_path(path, { :method => request.method })
params = ActionDispatch::Routing::Routes.recognize_path(path, { :method => request.method })
request.path_parameters = params.with_indifferent_access
request

View file

@ -188,11 +188,11 @@ module ActionDispatch
unless defined? @named_routes_configured
# install the named routes in this session instance.
klass = metaclass
ActionController::Routing::Routes.install_helpers(klass)
ActionDispatch::Routing::Routes.install_helpers(klass)
# the helpers are made protected by default--we make them public for
# easier access during testing and troubleshooting.
klass.module_eval { public *ActionController::Routing::Routes.named_routes.helpers }
klass.module_eval { public *ActionDispatch::Routing::Routes.named_routes.helpers }
@named_routes_configured = true
end
end

View file

@ -8,7 +8,7 @@ module ActionView
# Full usage example:
#
# config/routes.rb:
# ActionController::Routing::Routes.draw do |map|
# ActionDispatch::Routing::Routes.draw do |map|
# map.resources :posts
# map.root :controller => "posts"
# end

View file

@ -5,7 +5,7 @@ require 'active_support/core_ext/hash/keys'
module ActionView
module Helpers #:nodoc:
# Provides a set of methods for making links and getting URLs that
# depend on the routing subsystem (see ActionController::Routing).
# depend on the routing subsystem (see ActionDispatch::Routing).
# This allows you to use the same format for links in views
# and controllers.
module UrlHelper

View file

@ -152,7 +152,7 @@ module ActionView
end
def method_missing(selector, *args)
if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
if ActionDispatch::Routing::Routes.named_routes.helpers.include?(selector)
@controller.__send__(selector, *args)
else
super

View file

@ -76,7 +76,7 @@ class ActiveSupport::TestCase
# Hold off drawing routes until all the possible controller classes
# have been loaded.
setup_once do
ActionController::Routing::Routes.draw do |map|
ActionDispatch::Routing::Routes.draw do |map|
match ':controller(/:action(/:id))'
end
end
@ -92,7 +92,7 @@ class ActionController::IntegrationTest < ActiveSupport::TestCase
middleware.use "ActionDispatch::Cookies"
middleware.use "ActionDispatch::Flash"
middleware.use "ActionDispatch::Head"
}.build(routes || ActionController::Routing::Routes)
}.build(routes || ActionDispatch::Routing::Routes)
end
self.app = build_app
@ -118,19 +118,19 @@ class ActionController::IntegrationTest < ActiveSupport::TestCase
end
def with_routing(&block)
real_routes = ActionController::Routing::Routes
ActionController::Routing.module_eval { remove_const :Routes }
real_routes = ActionDispatch::Routing::Routes
ActionDispatch::Routing.module_eval { remove_const :Routes }
temporary_routes = ActionController::Routing::RouteSet.new
temporary_routes = ActionDispatch::Routing::RouteSet.new
self.class.app = self.class.build_app(temporary_routes)
ActionController::Routing.module_eval { const_set :Routes, temporary_routes }
ActionDispatch::Routing.module_eval { const_set :Routes, temporary_routes }
yield temporary_routes
ensure
if ActionController::Routing.const_defined? :Routes
ActionController::Routing.module_eval { remove_const :Routes }
if ActionDispatch::Routing.const_defined? :Routes
ActionDispatch::Routing.module_eval { remove_const :Routes }
end
ActionController::Routing.const_set(:Routes, real_routes) if real_routes
ActionDispatch::Routing.const_set(:Routes, real_routes) if real_routes
self.class.app = self.class.build_app
end
end

View file

@ -400,7 +400,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
map.resources :series
end
ActionController::Routing::Routes.install_helpers(self.class)
ActionDispatch::Routing::Routes.install_helpers(self.class)
yield
end
end
@ -422,7 +422,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
end
end
ActionController::Routing::Routes.install_helpers(self.class)
ActionDispatch::Routing::Routes.install_helpers(self.class)
yield
end
end
@ -441,7 +441,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
end
end
ActionController::Routing::Routes.install_helpers(self.class)
ActionDispatch::Routing::Routes.install_helpers(self.class)
yield
end
end

View file

@ -326,7 +326,7 @@ class RescueTest < ActionController::IntegrationTest
end
test 'rescue routing exceptions' do
@app = ActionDispatch::Rescue.new(ActionController::Routing::Routes) do
@app = ActionDispatch::Rescue.new(ActionDispatch::Routing::Routes) do
rescue_from ActionController::RoutingError, lambda { |env| [200, {"Content-Type" => "text/html"}, ["Gotcha!"]] }
end
@ -335,7 +335,7 @@ class RescueTest < ActionController::IntegrationTest
end
test 'unrescued exception' do
@app = ActionDispatch::Rescue.new(ActionController::Routing::Routes)
@app = ActionDispatch::Rescue.new(ActionDispatch::Routing::Routes)
assert_raise(ActionController::RoutingError) { get '/b00m' }
end

View file

@ -394,7 +394,7 @@ class ResourcesTest < ActionController::TestCase
assert_restful_routes_for :messages do |options|
assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get)
assert_raise(ActionController::RoutingError) do
ActionController::Routing::Routes.recognize_path("/messages/new", :method => :post)
ActionDispatch::Routing::Routes.recognize_path("/messages/new", :method => :post)
end
end
end
@ -504,7 +504,7 @@ class ResourcesTest < ActionController::TestCase
def test_restful_routes_dont_generate_duplicates
with_restful_routing :messages do
routes = ActionController::Routing::Routes.routes
routes = ActionDispatch::Routing::Routes.routes
routes.each do |route|
routes.each do |r|
next if route === r # skip the comparison instance

View file

@ -476,8 +476,8 @@ XML
end
def test_with_routing_places_routes_back
assert ActionController::Routing::Routes
routes_id = ActionController::Routing::Routes.object_id
assert ActionDispatch::Routing::Routes
routes_id = ActionDispatch::Routing::Routes.object_id
begin
with_routing { raise 'fail' }
@ -485,8 +485,8 @@ XML
rescue RuntimeError
end
assert ActionController::Routing::Routes
assert_equal routes_id, ActionController::Routing::Routes.object_id
assert ActionDispatch::Routing::Routes
assert_equal routes_id, ActionDispatch::Routing::Routes.object_id
end
def test_remote_addr

View file

@ -245,7 +245,7 @@ class WebServiceTest < ActionController::IntegrationTest
private
def with_params_parsers(parsers = {})
old_session = @integration_session
@app = ActionDispatch::ParamsParser.new(ActionController::Routing::Routes, parsers)
@app = ActionDispatch::ParamsParser.new(ActionDispatch::Routing::Routes, parsers)
reset!
yield
ensure

View file

@ -728,14 +728,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
private
def with_test_routes
real_routes, temp_routes = ActionController::Routing::Routes, Routes
real_routes, temp_routes = ActionDispatch::Routing::Routes, Routes
ActionController::Routing.module_eval { remove_const :Routes }
ActionController::Routing.module_eval { const_set :Routes, temp_routes }
ActionDispatch::Routing.module_eval { remove_const :Routes }
ActionDispatch::Routing.module_eval { const_set :Routes, temp_routes }
yield
ensure
ActionController::Routing.module_eval { remove_const :Routes }
ActionController::Routing.const_set(:Routes, real_routes)
ActionDispatch::Routing.module_eval { remove_const :Routes }
ActionDispatch::Routing.const_set(:Routes, real_routes)
end
end

View file

@ -1,3 +1,3 @@
ActionController::Routing::Routes.draw do |map|
ActionDispatch::Routing::Routes.draw do |map|
match '/rails/info/properties' => "rails/info#properties"
end
end

View file

@ -48,7 +48,7 @@ module Rails
end
def routes
::ActionController::Routing::Routes
::ActionDispatch::Routing::Routes
end
def railties

View file

@ -1,9 +1,9 @@
desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
task :routes => :environment do
Rails::Application.reload_routes!
all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
all_routes = ENV['CONTROLLER'] ? ActionDispatch::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionDispatch::Routing::Routes.routes
routes = all_routes.collect do |route|
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
name = ActionDispatch::Routing::Routes.named_routes.routes.index(route).to_s
reqs = route.requirements.empty? ? "" : route.requirements.inspect
{:name => name, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
end

View file

@ -14,7 +14,7 @@ class InfoControllerTest < ActionController::TestCase
tests Rails::InfoController
def setup
ActionController::Routing::Routes.draw do |map|
ActionDispatch::Routing::Routes.draw do |map|
match ':controller/:action'
end
@controller.stubs(:consider_all_requests_local? => false, :local_request? => true)

View file

@ -133,7 +133,7 @@ module RailtiesTest
end
end
ActionController::Routing::Routes.draw do
ActionDispatch::Routing::Routes.draw do
match "/sprokkit", :to => Sprokkit
end
RUBY
@ -170,7 +170,7 @@ module RailtiesTest
RUBY
@plugin.write "config/routes.rb", <<-RUBY
ActionController::Routing::Routes.draw do |map|
ActionDispatch::Routing::Routes.draw do |map|
match 'foo', :to => 'bar#index'
match 'bar', :to => 'bar#index'
end
@ -261,7 +261,7 @@ YAML
def test_namespaced_controllers_with_namespaced_routes
@plugin.write "config/routes.rb", <<-RUBY
ActionController::Routing::Routes.draw do
ActionDispatch::Routing::Routes.draw do
namespace :admin do
match "index", :to => "admin/foo#index"
end
@ -312,4 +312,4 @@ YAML
boot_rails
end
end
end
end