diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/integration.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/routing.rb | 19 | ||||
-rw-r--r-- | actionpack/lib/action_controller/url_rewriter.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/action_pack_assertions_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/routing_test.rb | 14 |
6 files changed, 31 insertions, 10 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 21df4be24a..fa72694ffe 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Add ActionController::Routing::Helpers, a module to contain common URL helpers such as polymorphic_url. [Nicholas Seckar] + * Included the HttpAuthentication plugin as part of core (ActionController::HttpAuthentication::Basic) [DHH] * Modernize documentation for form helpers. [jeremymcanally] diff --git a/actionpack/lib/action_controller/integration.rb b/actionpack/lib/action_controller/integration.rb index b6a883d58e..6092b87219 100644 --- a/actionpack/lib/action_controller/integration.rb +++ b/actionpack/lib/action_controller/integration.rb @@ -75,7 +75,7 @@ module ActionController unless defined? @named_routes_configured # install the named routes in this session instance. klass = class<<self; self; end - Routing::Routes.named_routes.install(klass) + Routing::Routes.install_helpers(klass) # the helpers are made protected by default--we make them public for # easier access during testing and troubleshooting. diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 1710ffcee9..9bbb51cfbf 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -252,7 +252,11 @@ module ActionController # The root paths which may contain controller files mattr_accessor :controller_paths self.controller_paths = [] - + + # A helper module to hold URL related helpers. + module Helpers + end + class << self def with_controllers(names) prior_controllers = @possible_controllers @@ -1134,15 +1138,20 @@ module ActionController def draw clear! yield Mapper.new(self) - named_routes.install + install_helpers end - + def clear! routes.clear named_routes.clear @combined_regexp = nil @routes_by_controller = nil end + + def install_helpers(destinations = [ActionController::Base, ActionView::Base]) + Array(destinations).each { |d| d.send :include, Helpers } + named_routes.install(destinations) + end def empty? routes.empty? @@ -1152,11 +1161,11 @@ module ActionController Routing.use_controllers! nil # Clear the controller cache so we may discover new ones clear! load_routes! - named_routes.install + install_helpers end alias reload load! - + def load_routes! if defined?(RAILS_ROOT) && defined?(::ActionController::Routing::Routes) && self == ::ActionController::Routing::Routes load File.join("#{RAILS_ROOT}/config/routes.rb") diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index 636fe55f97..384c818254 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -21,7 +21,7 @@ module ActionController self.default_url_options = {} def self.included(base) #:nodoc: - ActionController::Routing::Routes.named_routes.install base + ActionController::Routing::Routes.install_helpers base base.mattr_accessor :default_url_options base.default_url_options ||= default_url_options end diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index e4624484ec..1aefbfd677 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -209,7 +209,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase map.route_one 'route_one', :controller => 'action_pack_assertions', :action => 'nothing' map.connect ':controller/:action/:id' end - set.named_routes.install + set.install_helpers process :redirect_to_named_route assert_redirected_to 'http://test.host/route_one' diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 986737c4dc..658059cefe 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -207,7 +207,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase def setup_for_named_route x = Class.new x.send(:define_method, :url_for) {|x| x} - rs.named_routes.install(x) + rs.install_helpers(x) x end @@ -1417,7 +1417,7 @@ class RouteSetTest < Test::Unit::TestCase end klass = Class.new(MockController) - set.named_routes.install(klass) + set.install_helpers(klass) klass.new(set) end @@ -1885,4 +1885,14 @@ class RoutingTest < Test::Unit::TestCase assert_equal %w(vendor\\rails\\railties\\builtin\\rails_info vendor\\rails\\actionpack\\lib app\\controllers app\\helpers app\\models lib .), paths end + def test_routing_helper_module + assert_kind_of Module, ActionController::Routing::Helpers + + h = ActionController::Routing::Helpers + c = Class.new + assert ! c.ancestors.include?(h) + ActionController::Routing::Routes.install_helpers c + assert c.ancestors.include?(h) + end + end |