Skip to content

Commit

Permalink
Rename named_url_helpers to url_helpers and url_helpers to url_for
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlhuda committed Feb 26, 2010
1 parent f10a019 commit 98f77e0
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion actionmailer/lib/action_mailer/railtie.rb
Expand Up @@ -6,7 +6,7 @@ class Railtie < Rails::Railtie
railtie_name :action_mailer

initializer "action_mailer.url_for", :before => :load_environment_config do |app|
ActionMailer::Base.send(:include, app.routes.named_url_helpers)
ActionMailer::Base.send(:include, app.routes.url_helpers)
end

require "action_mailer/railties/log_subscriber"
Expand Down
2 changes: 1 addition & 1 deletion actionmailer/test/old_base/url_test.rb
Expand Up @@ -7,7 +7,7 @@ class WelcomeController < ActionController::Base
AppRoutes = ActionDispatch::Routing::RouteSet.new

class ActionMailer::Base
include AppRoutes.named_url_helpers
include AppRoutes.url_helpers
end

class TestMailer < ActionMailer::Base
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/metal/url_for.rb
Expand Up @@ -15,7 +15,7 @@ def merge_options(options)

def _router
raise "In order to use #url_for, you must include the helpers of a particular " \
"router. For instance, `include Rails.application.router.named_url_helpers"
"router. For instance, `include Rails.application.routes.url_helpers"
end
end
end
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/railties/url_helpers.rb
Expand Up @@ -5,7 +5,7 @@ def self.with(router)
Module.new do
define_method(:inherited) do |klass|
super(klass)
klass.send(:include, router.named_url_helpers)
klass.send(:include, router.url_helpers)
end
end
end
Expand Down
11 changes: 5 additions & 6 deletions actionpack/lib/action_dispatch/routing/route_set.rb
Expand Up @@ -259,9 +259,8 @@ def install_helpers(destinations = [ActionController::Base, ActionView::Base], r
named_routes.install(destinations, regenerate_code)
end

# ROUTES TODO: Revisit the name of these methods
def url_helpers
@url_helpers ||= begin
def url_for
@url_for ||= begin
router = self
Module.new do
extend ActiveSupport::Concern
Expand All @@ -272,13 +271,13 @@ def url_helpers
end
end

def named_url_helpers
@named_url_helpers ||= begin
def url_helpers
@url_helpers ||= begin
router = self

Module.new do
extend ActiveSupport::Concern
include router.url_helpers
include router.url_for

# ROUTES TODO: install_helpers isn't great... can we make a module with the stuff that
# we can include?
Expand Down
6 changes: 3 additions & 3 deletions actionpack/lib/action_dispatch/testing/assertions/routing.rb
Expand Up @@ -145,14 +145,14 @@ def with_routing
old_routes, @router = @router, ActionDispatch::Routing::RouteSet.new
old_controller, @controller = @controller, @controller.clone if @controller
# ROUTES TODO: Figure out this insanity
silence_warnings { ::ActionController.const_set(:UrlFor, @router.named_url_helpers) }
silence_warnings { ::ActionController.const_set(:UrlFor, @router.url_helpers) }
_router = @router
@controller.singleton_class.send(:send, :include, @router.named_url_helpers) if @controller
@controller.singleton_class.send(:send, :include, @router.url_helpers) if @controller
yield @router
ensure
@router = old_routes
@controller = old_controller if @controller
silence_warnings { ::ActionController.const_set(:UrlFor, @router.named_url_helpers) } if @router
silence_warnings { ::ActionController.const_set(:UrlFor, @router.url_helpers) } if @router
end

def method_missing(selector, *args, &block)
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/abstract_unit.rb
Expand Up @@ -256,7 +256,7 @@ def assert_template(options = {}, message = nil)

# ROUTES TODO: Cleaner way to do this?
module ActionController
UrlFor = SharedTestRoutes.named_url_helpers
UrlFor = SharedTestRoutes.url_helpers
class Base
include UrlFor
end
Expand Down
6 changes: 3 additions & 3 deletions actionpack/test/activerecord/polymorphic_routes_test.rb
Expand Up @@ -400,7 +400,7 @@ def with_test_routes(options = {})
map.resources :series
end

self.class.send(:include, @router.named_url_helpers)
self.class.send(:include, @router.url_helpers)
yield
end
end
Expand All @@ -422,7 +422,7 @@ def with_admin_test_routes(options = {})
end
end

self.class.send(:include, @router.named_url_helpers)
self.class.send(:include, @router.url_helpers)
yield
end
end
Expand All @@ -441,7 +441,7 @@ def with_admin_and_site_test_routes(options = {})
end
end

self.class.send(:include, @router.named_url_helpers)
self.class.send(:include, @router.url_helpers)
yield
end
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/caching_test.rb
Expand Up @@ -512,7 +512,7 @@ def reset!
@response = ActionController::TestResponse.new
@controller = ActionCachingTestController.new
# ROUTES TODO: It seems bad to explicitly remix in the class
@controller.singleton_class.send(:include, @router.named_url_helpers)
@controller.singleton_class.send(:include, @router.url_helpers)
@request.host = 'hostname.com'
end

Expand Down
8 changes: 4 additions & 4 deletions actionpack/test/controller/integration_test.rb
Expand Up @@ -221,7 +221,7 @@ def test_integration_methods_called
end

class IntegrationProcessTest < ActionController::IntegrationTest
include SharedTestRoutes.named_url_helpers
include SharedTestRoutes.url_helpers

class IntegrationController < ActionController::Base
def get
Expand Down Expand Up @@ -388,23 +388,23 @@ def with_test_route_set
with_routing do |set|
controller = ::IntegrationProcessTest::IntegrationController.clone
controller.class_eval do
include set.named_url_helpers
include set.url_helpers
end

set.draw do |map|
match ':action', :to => controller
get 'get/:action', :to => controller
end

self.singleton_class.send(:include, set.named_url_helpers)
self.singleton_class.send(:include, set.url_helpers)

yield
end
end
end

class MetalIntegrationTest < ActionController::IntegrationTest
include SharedTestRoutes.named_url_helpers
include SharedTestRoutes.url_helpers

class Poller
def self.call(env)
Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/controller/resources_test.rb
Expand Up @@ -1231,7 +1231,7 @@ def assert_restful_named_routes_for(controller_name, singular_name = nil, option

@controller = "#{options[:options][:controller].camelize}Controller".constantize.new
# ROUTES TODO: Figure out a way to not extend the routing helpers here
@controller.singleton_class.send(:include, @router.named_url_helpers)
@controller.singleton_class.send(:include, @router.url_helpers)
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
get :index, options[:options]
Expand Down Expand Up @@ -1301,7 +1301,7 @@ def assert_singleton_routes_for(singleton_name, options = {})
def assert_singleton_named_routes_for(singleton_name, options = {})
(options[:options] ||= {})[:controller] ||= singleton_name.to_s.pluralize
@controller = "#{options[:options][:controller].camelize}Controller".constantize.new
@controller.singleton_class.send(:include, @router.named_url_helpers)
@controller.singleton_class.send(:include, @router.url_helpers)
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
get :show, options[:options]
Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/controller/routing_test.rb
Expand Up @@ -251,7 +251,7 @@ def test_optimised_named_route_with_host

def setup_for_named_route
inst = MockController.clone.new
inst.class.send(:include, rs.named_url_helpers)
inst.class.send(:include, rs.url_helpers)
inst
end

Expand Down Expand Up @@ -741,7 +741,7 @@ def setup_named_route_test
map.users '/admin/users', :controller => 'admin/users', :action => 'index'
end

MockController.clone.new.tap { |inst| inst.class.send(:include, set.named_url_helpers)}
MockController.clone.new.tap { |inst| inst.class.send(:include, set.url_helpers)}
end

def test_named_route_hash_access_method
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/dispatch/routing_test.rb
Expand Up @@ -164,7 +164,7 @@ def app
Routes
end

include Routes.named_url_helpers
include Routes.url_helpers

def test_logout
with_test_routes do
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/test_help.rb
Expand Up @@ -31,7 +31,7 @@ class ActionController::TestCase
end

class ActionDispatch::IntegrationTest
include Rails.application.routes.named_url_helpers
include Rails.application.routes.url_helpers
end

begin
Expand Down
2 changes: 1 addition & 1 deletion railties/test/rails_info_controller_test.rb
Expand Up @@ -20,7 +20,7 @@ def setup
@controller.stubs(:consider_all_requests_local? => false, :local_request? => true)
@router = Rails.application.routes

Rails::InfoController.send(:include, @router.named_url_helpers)
Rails::InfoController.send(:include, @router.url_helpers)
end

test "info controller does not allow remote requests" do
Expand Down

2 comments on commit 98f77e0

@josh
Copy link
Contributor

@josh josh commented on 98f77e0 Feb 27, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go with "routes.helper"

@carllerche
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems better

Please sign in to comment.