Skip to content
Browse files

Find all controllers in memory to use for routing

  • Loading branch information...
1 parent f987e85 commit 15ab3a98a1b6f9b829060ba974048b33466f6814 @josh josh committed Nov 23, 2009
View
19 actionpack/lib/action_dispatch/routing.rb
@@ -280,6 +280,10 @@ def controller_constraints
Regexp.union(*possible_controllers.collect { |n| Regexp.escape(n) })
end
+ def clear_controller_cache!
+ @possible_controllers = nil
+ end
+
# Returns an array of paths, cleaned of double-slashes and relative path references.
# * "\\\" and "//" become "\\" or "/".
# * "/foo/bar/../config" becomes "/foo/config".
@@ -307,8 +311,15 @@ def possible_controllers
unless @possible_controllers
@possible_controllers = []
- paths = controller_paths.select { |path| File.directory?(path) && path != "." }
+ # Find any controller classes already in memory
+ ActionController::Base.subclasses.each do |klass|
+ controller_name = klass.underscore
+ controller_name.gsub!(/_controller\Z/, '')
+ @possible_controllers << controller_name
+ end
+ # Find controllers in controllers/ directory
+ paths = controller_paths.select { |path| File.directory?(path) && path != "." }
seen_paths = Hash.new {|h, k| h[k] = true; false}
normalize_paths(paths).each do |load_path|
Dir["#{load_path}/**/*_controller.rb"].collect do |path|
@@ -326,12 +337,6 @@ def possible_controllers
end
@possible_controllers
end
-
- # Replaces the internal list of controllers available to ActionController::Routing with the passed argument.
- # ActionController::Routing.use_controllers!([ "posts", "comments", "admin/comments" ])
- def use_controllers!(controller_names)
- @possible_controllers = controller_names
- end
end
end
end
View
4 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -246,7 +246,9 @@ def configuration_file
end
def load!
- Routing.use_controllers!(nil) # Clear the controller cache so we may discover new ones
+ # Clear the controller cache so we may discover new ones
+ Routing.clear_controller_cache!
+
load_routes!
end
View
12 actionpack/test/abstract_unit.rb
@@ -191,20 +191,8 @@ class ::ApplicationController < ActionController::Base
end
module ActionController
- module Routing
- def self.possible_controllers
- @@possible_controllers ||= []
- end
- end
-
class Base
include ActionController::Testing
-
- def self.inherited(klass)
- name = klass.name.underscore.sub(/_controller$/, '')
- ActionController::Routing.possible_controllers << name unless name.blank?
- super
- end
end
Base.view_paths = FIXTURE_LOAD_PATH
View
5 railties/test/rails_info_controller_test.rb
@@ -14,17 +14,12 @@ class InfoControllerTest < ActionController::TestCase
tests Rails::InfoController
def setup
- ActionController::Routing.use_controllers!(['rails/info'])
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
end
@controller.stubs(:consider_all_requests_local => false, :local_request? => true)
end
- def teardown
- ActionController::Routing.use_controllers! nil
- end
-
test "info controller does not allow remote requests" do
@controller.stubs(:consider_all_requests_local => false, :local_request? => false)
get :properties

1 comment on commit 15ab3a9

@rubys
rubys commented on 15ab3a9 Nov 25, 2009

This commit causes the tests in the following step to fail:

http://intertwingly.net/projects/AWDwR3/checkdepot.html#section-21

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