Skip to content
This repository
Browse code

Use ActionDispatch::Routing everywhere

  • Loading branch information...
commit 6bc24d40d56332593bc22612d4618a2f80b1d91b 1 parent 4cdfe98
Martin Schürrer authored February 21, 2010 Yehuda Katz committed February 21, 2010

Showing 24 changed files with 64 additions and 59 deletions. Show diff stats Hide diff stats

  1. 2  actionmailer/test/old_base/url_test.rb
  2. 1  actionpack/lib/action_controller/deprecated.rb
  3. 4  actionpack/lib/action_controller/metal/compatibility.rb
  4. 4  actionpack/lib/action_controller/metal/url_for.rb
  5. 2  actionpack/lib/action_controller/test_case.rb
  6. 1  actionpack/lib/action_dispatch/routing.rb
  7. 5  actionpack/lib/action_dispatch/routing/routes.rb
  8. 22  actionpack/lib/action_dispatch/testing/assertions/routing.rb
  9. 4  actionpack/lib/action_dispatch/testing/integration.rb
  10. 2  actionpack/lib/action_view/helpers/atom_feed_helper.rb
  11. 2  actionpack/lib/action_view/helpers/url_helper.rb
  12. 2  actionpack/lib/action_view/test_case.rb
  13. 18  actionpack/test/abstract_unit.rb
  14. 6  actionpack/test/activerecord/polymorphic_routes_test.rb
  15. 4  actionpack/test/controller/rescue_test.rb
  16. 4  actionpack/test/controller/resources_test.rb
  17. 8  actionpack/test/controller/test_test.rb
  18. 2  actionpack/test/controller/webservice_test.rb
  19. 10  actionpack/test/dispatch/routing_test.rb
  20. 4  railties/builtin/routes.rb
  21. 2  railties/lib/rails/application.rb
  22. 4  railties/lib/rails/tasks/routes.rake
  23. 2  railties/test/rails_info_controller_test.rb
  24. 8  railties/test/railties/shared_tests.rb
2  actionmailer/test/old_base/url_test.rb
@@ -61,7 +61,7 @@ def teardown
61 61
   def test_signed_up_with_url
62 62
     TestMailer.delivery_method = :test
63 63
     
64  
-    ActionController::Routing::Routes.draw do |map|
  64
+    ActionDispatch::Routing::Routes.draw do |map|
65 65
       map.connect ':controller/:action/:id'
66 66
       map.welcome 'welcome', :controller=>"foo", :action=>"bar"
67 67
     end
1  actionpack/lib/action_controller/deprecated.rb
... ...
@@ -1,5 +1,4 @@
1 1
 ActionController::AbstractRequest = ActionController::Request = ActionDispatch::Request
2 2
 ActionController::AbstractResponse = ActionController::Response = ActionDispatch::Response
3 3
 ActionController::Routing = ActionDispatch::Routing
4  
-ActionController::Routing::Routes = ActionDispatch::Routing::RouteSet.new
5 4
 ActionController::UrlWriter = ActionController::UrlFor
4  actionpack/lib/action_controller/metal/compatibility.rb
@@ -20,8 +20,8 @@ class ::ActionController::ActionControllerError < StandardError #:nodoc:
20 20
 
21 21
       class << self
22 22
         delegate :default_charset=, :to => "ActionDispatch::Response"
23  
-        delegate :resources_path_names, :to => "ActionController::Routing::Routes"
24  
-        delegate :resources_path_names=, :to => "ActionController::Routing::Routes"
  23
+        delegate :resources_path_names, :to => "ActionDispatch::Routing::Routes"
  24
+        delegate :resources_path_names=, :to => "ActionDispatch::Routing::Routes"
25 25
       end
26 26
 
27 27
       # cattr_reader :protected_instance_variables
4  actionpack/lib/action_controller/metal/url_for.rb
@@ -6,7 +6,7 @@ module ActionController
6 6
   # is also possible: an URL can be generated from one of your routing definitions.
7 7
   # URL generation functionality is centralized in this module.
8 8
   #
9  
-  # See ActionController::Routing and ActionController::Resources for general
  9
+  # See ActionDispatch::Routing and ActionController::Resources for general
10 10
   # information about routing and routes.rb.
11 11
   #
12 12
   # <b>Tip:</b> If you need to generate URLs from your models or some other place,
@@ -87,7 +87,7 @@ module UrlFor
87 87
     extend ActiveSupport::Concern
88 88
 
89 89
     included do
90  
-      ActionController::Routing::Routes.install_helpers(self)
  90
+      ActionDispatch::Routing::Routes.install_helpers(self)
91 91
 
92 92
       # Including in a class uses an inheritable hash. Modules get a plain hash.
93 93
       if respond_to?(:class_attribute)
2  actionpack/lib/action_controller/test_case.rb
@@ -19,7 +19,7 @@ def self.new_escaped(strings)
19 19
 
20 20
     def assign_parameters(controller_path, action, parameters = {})
21 21
       parameters = parameters.symbolize_keys.merge(:controller => controller_path, :action => action)
22  
-      extra_keys = ActionController::Routing::Routes.extra_keys(parameters)
  22
+      extra_keys = ActionDispatch::Routing::Routes.extra_keys(parameters)
23 23
       non_path_parameters = get? ? query_parameters : request_parameters
24 24
       parameters.each do |key, value|
25 25
         if value.is_a? Fixnum
1  actionpack/lib/action_dispatch/routing.rb
@@ -204,6 +204,7 @@ module Routing
204 204
     autoload :DeprecatedMapper, 'action_dispatch/routing/deprecated_mapper'
205 205
     autoload :Mapper, 'action_dispatch/routing/mapper'
206 206
     autoload :Route, 'action_dispatch/routing/route'
  207
+    autoload :Routes, 'action_dispatch/routing/routes'
207 208
     autoload :RouteSet, 'action_dispatch/routing/route_set'
208 209
 
209 210
     SEPARATORS = %w( / . ? )
5  actionpack/lib/action_dispatch/routing/routes.rb
... ...
@@ -0,0 +1,5 @@
  1
+# A singleton that stores the current route set
  2
+ActionDispatch::Routing::Routes = ActionDispatch::Routing::RouteSet.new
  3
+
  4
+# To preserve compatibility with pre-3.0 Rails action_controller/deprecated.rb
  5
+# defines ActionDispatch::Routing::Routes as an alias
22  actionpack/lib/action_dispatch/testing/assertions/routing.rb
@@ -80,7 +80,7 @@ def assert_generates(expected_path, options, defaults={}, extras = {}, message=n
80 80
         expected_path = "/#{expected_path}" unless expected_path[0] == ?/
81 81
         # Load routes.rb if it hasn't been loaded.
82 82
 
83  
-        generated_path, extra_keys = ActionController::Routing::Routes.generate_extras(options, defaults)
  83
+        generated_path, extra_keys = ActionDispatch::Routing::Routes.generate_extras(options, defaults)
84 84
         found_extras = options.reject {|k, v| ! extra_keys.include? k}
85 85
 
86 86
         msg = build_message(message, "found extras <?>, not <?>", found_extras, extras)
@@ -125,7 +125,7 @@ def assert_routing(path, options, defaults={}, extras={}, message=nil)
125 125
       end
126 126
 
127 127
       # A helper to make it easier to test different route configurations.
128  
-      # This method temporarily replaces ActionController::Routing::Routes
  128
+      # This method temporarily replaces ActionDispatch::Routing::Routes
129 129
       # with a new RouteSet instance.
130 130
       #
131 131
       # The new instance is yielded to the passed block. Typically the block
@@ -142,22 +142,22 @@ def assert_routing(path, options, defaults={}, extras={}, message=nil)
142 142
       #   end
143 143
       #
144 144
       def with_routing
145  
-        real_routes = ActionController::Routing::Routes
146  
-        ActionController::Routing.module_eval { remove_const :Routes }
  145
+        real_routes = ActionDispatch::Routing::Routes
  146
+        ActionDispatch::Routing.module_eval { remove_const :Routes }
147 147
 
148  
-        temporary_routes = ActionController::Routing::RouteSet.new
149  
-        ActionController::Routing.module_eval { const_set :Routes, temporary_routes }
  148
+        temporary_routes = ActionDispatch::Routing::RouteSet.new
  149
+        ActionDispatch::Routing.module_eval { const_set :Routes, temporary_routes }
150 150
 
151 151
         yield temporary_routes
152 152
       ensure
153  
-        if ActionController::Routing.const_defined? :Routes
154  
-          ActionController::Routing.module_eval { remove_const :Routes }
  153
+        if ActionDispatch::Routing.const_defined? :Routes
  154
+          ActionDispatch::Routing.module_eval { remove_const :Routes }
155 155
         end
156  
-        ActionController::Routing.const_set(:Routes, real_routes) if real_routes
  156
+        ActionDispatch::Routing.const_set(:Routes, real_routes) if real_routes
157 157
       end
158 158
 
159 159
       def method_missing(selector, *args, &block)
160  
-        if @controller && ActionController::Routing::Routes.named_routes.helpers.include?(selector)
  160
+        if @controller && ActionDispatch::Routing::Routes.named_routes.helpers.include?(selector)
161 161
           @controller.send(selector, *args, &block)
162 162
         else
163 163
           super
@@ -174,7 +174,7 @@ def recognized_request_for(path, request_method = nil)
174 174
           request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method
175 175
           request.path = path
176 176
 
177  
-          params = ActionController::Routing::Routes.recognize_path(path, { :method => request.method })
  177
+          params = ActionDispatch::Routing::Routes.recognize_path(path, { :method => request.method })
178 178
           request.path_parameters = params.with_indifferent_access
179 179
 
180 180
           request
4  actionpack/lib/action_dispatch/testing/integration.rb
@@ -188,11 +188,11 @@ def reset!
188 188
         unless defined? @named_routes_configured
189 189
           # install the named routes in this session instance.
190 190
           klass = metaclass
191  
-          ActionController::Routing::Routes.install_helpers(klass)
  191
+          ActionDispatch::Routing::Routes.install_helpers(klass)
192 192
 
193 193
           # the helpers are made protected by default--we make them public for
194 194
           # easier access during testing and troubleshooting.
195  
-          klass.module_eval { public *ActionController::Routing::Routes.named_routes.helpers }
  195
+          klass.module_eval { public *ActionDispatch::Routing::Routes.named_routes.helpers }
196 196
           @named_routes_configured = true
197 197
         end
198 198
       end
2  actionpack/lib/action_view/helpers/atom_feed_helper.rb
@@ -8,7 +8,7 @@ module AtomFeedHelper
8 8
       # Full usage example:
9 9
       #
10 10
       #   config/routes.rb:
11  
-      #     ActionController::Routing::Routes.draw do |map|
  11
+      #     ActionDispatch::Routing::Routes.draw do |map|
12 12
       #       map.resources :posts
13 13
       #       map.root :controller => "posts"
14 14
       #     end
2  actionpack/lib/action_view/helpers/url_helper.rb
@@ -5,7 +5,7 @@
5 5
 module ActionView
6 6
   module Helpers #:nodoc:
7 7
     # Provides a set of methods for making links and getting URLs that
8  
-    # depend on the routing subsystem (see ActionController::Routing).
  8
+    # depend on the routing subsystem (see ActionDispatch::Routing).
9 9
     # This allows you to use the same format for links in views
10 10
     # and controllers.
11 11
     module UrlHelper
2  actionpack/lib/action_view/test_case.rb
@@ -152,7 +152,7 @@ def _assigns
152 152
       end
153 153
 
154 154
       def method_missing(selector, *args)
155  
-        if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
  155
+        if ActionDispatch::Routing::Routes.named_routes.helpers.include?(selector)
156 156
           @controller.__send__(selector, *args)
157 157
         else
158 158
           super
18  actionpack/test/abstract_unit.rb
@@ -76,7 +76,7 @@ class ActiveSupport::TestCase
76 76
   # Hold off drawing routes until all the possible controller classes
77 77
   # have been loaded.
78 78
   setup_once do
79  
-    ActionController::Routing::Routes.draw do |map|
  79
+    ActionDispatch::Routing::Routes.draw do |map|
80 80
       match ':controller(/:action(/:id))'
81 81
     end
82 82
   end
@@ -92,7 +92,7 @@ def self.build_app(routes = nil)
92 92
       middleware.use "ActionDispatch::Cookies"
93 93
       middleware.use "ActionDispatch::Flash"
94 94
       middleware.use "ActionDispatch::Head"
95  
-    }.build(routes || ActionController::Routing::Routes)
  95
+    }.build(routes || ActionDispatch::Routing::Routes)
96 96
   end
97 97
 
98 98
   self.app = build_app
@@ -118,19 +118,19 @@ def self.stub_controllers
118 118
   end
119 119
 
120 120
   def with_routing(&block)
121  
-    real_routes = ActionController::Routing::Routes
122  
-    ActionController::Routing.module_eval { remove_const :Routes }
  121
+    real_routes = ActionDispatch::Routing::Routes
  122
+    ActionDispatch::Routing.module_eval { remove_const :Routes }
123 123
 
124  
-    temporary_routes = ActionController::Routing::RouteSet.new
  124
+    temporary_routes = ActionDispatch::Routing::RouteSet.new
125 125
     self.class.app = self.class.build_app(temporary_routes)
126  
-    ActionController::Routing.module_eval { const_set :Routes, temporary_routes }
  126
+    ActionDispatch::Routing.module_eval { const_set :Routes, temporary_routes }
127 127
 
128 128
     yield temporary_routes
129 129
   ensure
130  
-    if ActionController::Routing.const_defined? :Routes
131  
-      ActionController::Routing.module_eval { remove_const :Routes }
  130
+    if ActionDispatch::Routing.const_defined? :Routes
  131
+      ActionDispatch::Routing.module_eval { remove_const :Routes }
132 132
     end
133  
-    ActionController::Routing.const_set(:Routes, real_routes) if real_routes
  133
+    ActionDispatch::Routing.const_set(:Routes, real_routes) if real_routes
134 134
     self.class.app = self.class.build_app
135 135
   end
136 136
 end
6  actionpack/test/activerecord/polymorphic_routes_test.rb
@@ -400,7 +400,7 @@ def with_test_routes(options = {})
400 400
         map.resources :series
401 401
       end
402 402
 
403  
-      ActionController::Routing::Routes.install_helpers(self.class)
  403
+      ActionDispatch::Routing::Routes.install_helpers(self.class)
404 404
       yield
405 405
     end
406 406
   end
@@ -422,7 +422,7 @@ def with_admin_test_routes(options = {})
422 422
         end
423 423
       end
424 424
 
425  
-      ActionController::Routing::Routes.install_helpers(self.class)
  425
+      ActionDispatch::Routing::Routes.install_helpers(self.class)
426 426
       yield
427 427
     end
428 428
   end
@@ -441,7 +441,7 @@ def with_admin_and_site_test_routes(options = {})
441 441
         end
442 442
       end
443 443
 
444  
-      ActionController::Routing::Routes.install_helpers(self.class)
  444
+      ActionDispatch::Routing::Routes.install_helpers(self.class)
445 445
       yield
446 446
     end
447 447
   end
4  actionpack/test/controller/rescue_test.rb
@@ -326,7 +326,7 @@ def show_errors(exception)
326 326
   end
327 327
 
328 328
   test 'rescue routing exceptions' do
329  
-    @app = ActionDispatch::Rescue.new(ActionController::Routing::Routes) do
  329
+    @app = ActionDispatch::Rescue.new(ActionDispatch::Routing::Routes) do
330 330
       rescue_from ActionController::RoutingError, lambda { |env| [200, {"Content-Type" => "text/html"}, ["Gotcha!"]] }
331 331
     end
332 332
 
@@ -335,7 +335,7 @@ def show_errors(exception)
335 335
   end
336 336
 
337 337
   test 'unrescued exception' do
338  
-    @app = ActionDispatch::Rescue.new(ActionController::Routing::Routes)
  338
+    @app = ActionDispatch::Rescue.new(ActionDispatch::Routing::Routes)
339 339
     assert_raise(ActionController::RoutingError) { get '/b00m' }
340 340
   end
341 341
 
4  actionpack/test/controller/resources_test.rb
@@ -394,7 +394,7 @@ def test_override_new_method
394 394
       assert_restful_routes_for :messages do |options|
395 395
         assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get)
396 396
         assert_raise(ActionController::RoutingError) do
397  
-          ActionController::Routing::Routes.recognize_path("/messages/new", :method => :post)
  397
+          ActionDispatch::Routing::Routes.recognize_path("/messages/new", :method => :post)
398 398
         end
399 399
       end
400 400
     end
@@ -504,7 +504,7 @@ def test_shallow_nested_restful_routes_with_namespaces
504 504
 
505 505
   def test_restful_routes_dont_generate_duplicates
506 506
     with_restful_routing :messages do
507  
-      routes = ActionController::Routing::Routes.routes
  507
+      routes = ActionDispatch::Routing::Routes.routes
508 508
       routes.each do |route|
509 509
         routes.each do |r|
510 510
           next if route === r # skip the comparison instance
8  actionpack/test/controller/test_test.rb
@@ -476,8 +476,8 @@ def test_assert_realistic_path_parameters
476 476
   end
477 477
 
478 478
   def test_with_routing_places_routes_back
479  
-    assert ActionController::Routing::Routes
480  
-    routes_id = ActionController::Routing::Routes.object_id
  479
+    assert ActionDispatch::Routing::Routes
  480
+    routes_id = ActionDispatch::Routing::Routes.object_id
481 481
 
482 482
     begin
483 483
       with_routing { raise 'fail' }
@@ -485,8 +485,8 @@ def test_with_routing_places_routes_back
485 485
     rescue RuntimeError
486 486
     end
487 487
 
488  
-    assert ActionController::Routing::Routes
489  
-    assert_equal routes_id, ActionController::Routing::Routes.object_id
  488
+    assert ActionDispatch::Routing::Routes
  489
+    assert_equal routes_id, ActionDispatch::Routing::Routes.object_id
490 490
   end
491 491
 
492 492
   def test_remote_addr
2  actionpack/test/controller/webservice_test.rb
@@ -245,7 +245,7 @@ def test_typecast_as_yaml
245 245
   private
246 246
     def with_params_parsers(parsers = {})
247 247
       old_session = @integration_session
248  
-      @app = ActionDispatch::ParamsParser.new(ActionController::Routing::Routes, parsers)
  248
+      @app = ActionDispatch::ParamsParser.new(ActionDispatch::Routing::Routes, parsers)
249 249
       reset!
250 250
       yield
251 251
     ensure
10  actionpack/test/dispatch/routing_test.rb
@@ -728,14 +728,14 @@ def test_nested_optional_scoped_path
728 728
 
729 729
   private
730 730
     def with_test_routes
731  
-      real_routes, temp_routes = ActionController::Routing::Routes, Routes
  731
+      real_routes, temp_routes = ActionDispatch::Routing::Routes, Routes
732 732
 
733  
-      ActionController::Routing.module_eval { remove_const :Routes }
734  
-      ActionController::Routing.module_eval { const_set :Routes, temp_routes }
  733
+      ActionDispatch::Routing.module_eval { remove_const :Routes }
  734
+      ActionDispatch::Routing.module_eval { const_set :Routes, temp_routes }
735 735
 
736 736
       yield
737 737
     ensure
738  
-      ActionController::Routing.module_eval { remove_const :Routes }
739  
-      ActionController::Routing.const_set(:Routes, real_routes)
  738
+      ActionDispatch::Routing.module_eval { remove_const :Routes }
  739
+      ActionDispatch::Routing.const_set(:Routes, real_routes)
740 740
     end
741 741
 end
4  railties/builtin/routes.rb
... ...
@@ -1,3 +1,3 @@
1  
-ActionController::Routing::Routes.draw do |map|
  1
+ActionDispatch::Routing::Routes.draw do |map|
2 2
   match '/rails/info/properties' => "rails/info#properties"
3  
-end
  3
+end
2  railties/lib/rails/application.rb
@@ -48,7 +48,7 @@ def require_environment!
48 48
     end
49 49
 
50 50
     def routes
51  
-      ::ActionController::Routing::Routes
  51
+      ::ActionDispatch::Routing::Routes
52 52
     end
53 53
 
54 54
     def railties
4  railties/lib/rails/tasks/routes.rake
... ...
@@ -1,9 +1,9 @@
1 1
 desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
2 2
 task :routes => :environment do
3 3
   Rails::Application.reload_routes!
4  
-  all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
  4
+  all_routes = ENV['CONTROLLER'] ? ActionDispatch::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionDispatch::Routing::Routes.routes
5 5
   routes = all_routes.collect do |route|
6  
-    name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
  6
+    name = ActionDispatch::Routing::Routes.named_routes.routes.index(route).to_s
7 7
     reqs = route.requirements.empty? ? "" : route.requirements.inspect
8 8
     {:name => name, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
9 9
   end
2  railties/test/rails_info_controller_test.rb
@@ -14,7 +14,7 @@ class InfoControllerTest < ActionController::TestCase
14 14
   tests Rails::InfoController
15 15
 
16 16
   def setup
17  
-    ActionController::Routing::Routes.draw do |map|
  17
+    ActionDispatch::Routing::Routes.draw do |map|
18 18
       match ':controller/:action'
19 19
     end
20 20
     @controller.stubs(:consider_all_requests_local? => false, :local_request? => true)
8  railties/test/railties/shared_tests.rb
@@ -133,7 +133,7 @@ def self.call(env)
133 133
           end
134 134
         end
135 135
 
136  
-        ActionController::Routing::Routes.draw do
  136
+        ActionDispatch::Routing::Routes.draw do
137 137
           match "/sprokkit", :to => Sprokkit
138 138
         end
139 139
       RUBY
@@ -170,7 +170,7 @@ def index
170 170
       RUBY
171 171
 
172 172
       @plugin.write "config/routes.rb", <<-RUBY
173  
-        ActionController::Routing::Routes.draw do |map|
  173
+        ActionDispatch::Routing::Routes.draw do |map|
174 174
           match 'foo', :to => 'bar#index'
175 175
           match 'bar', :to => 'bar#index'
176 176
         end
@@ -261,7 +261,7 @@ def self.call(env)
261 261
 
262 262
     def test_namespaced_controllers_with_namespaced_routes
263 263
       @plugin.write "config/routes.rb", <<-RUBY
264  
-        ActionController::Routing::Routes.draw do
  264
+        ActionDispatch::Routing::Routes.draw do
265 265
           namespace :admin do
266 266
             match "index", :to => "admin/foo#index"
267 267
           end
@@ -312,4 +312,4 @@ def call(env)
312 312
       boot_rails
313 313
     end
314 314
   end
315  
-end
  315
+end

0 notes on commit 6bc24d4

Please sign in to comment.
Something went wrong with that request. Please try again.