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

Final pass at removing the router from a global constant

This commit is contained in:
Carlhuda 2010-02-25 16:48:36 -08:00
parent 36fd9efb5e
commit fc4582fb66
9 changed files with 72 additions and 12 deletions

View file

@ -1,5 +1,5 @@
require "action_controller"
require "rails"
require "action_controller"
require "action_view/railtie"
require "active_support/core_ext/class/subclasses"
@ -8,6 +8,8 @@ module ActionController
railtie_name :action_controller
require "action_controller/railties/log_subscriber"
require "action_controller/railties/url_helpers"
log_subscriber ActionController::Railties::LogSubscriber.new
initializer "action_controller.logger" do
@ -27,5 +29,9 @@ module ActionController
initializer "action_controller.set_helpers_path" do |app|
ActionController::Base.helpers_path = app.config.paths.app.helpers.to_a
end
initializer "action_controller.url_helpers" do |app|
ActionController::Base.extend ::ActionController::Railtie::UrlHelpers.with(app.routes)
end
end
end
end

View file

@ -0,0 +1,14 @@
module ActionController
class Railtie
module UrlHelpers
def self.with(router)
Module.new do
define_method(:inherited) do |klass|
super
klass.send(:include, router.named_url_helpers)
end
end
end
end
end
end

View file

@ -204,7 +204,6 @@ 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'
autoload :UrlFor, 'action_dispatch/routing/url_for'

View file

@ -1,5 +0,0 @@
# 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

@ -125,7 +125,7 @@ module ActionDispatch
end
# A helper to make it easier to test different route configurations.
# This method temporarily replaces ActionDispatch::Routing::Routes
# This method temporarily replaces @router
# with a new RouteSet instance.
#
# The new instance is yielded to the passed block. Typically the block

View file

@ -188,11 +188,9 @@ module ActionDispatch
unless defined? @named_routes_configured
# install the named routes in this session instance.
klass = singleton_class
# 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 *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:
# ActionDispatch::Routing::Routes.draw do |map|
# Basecamp::Application.routes.draw do |map|
# map.resources :posts
# map.root :controller => "posts"
# end

View file

@ -24,6 +24,12 @@ if defined?(ActiveRecord)
end
end
class ActionController::TestCase
setup do
@router = Rails.application.routes
end
end
begin
require_library_or_gem 'ruby-debug'
Debugger.start

View file

@ -0,0 +1,42 @@
require 'isolation/abstract_unit'
module ApplicationTests
class UrlGenerationTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
def app
Rails.application
end
test "it works" do
boot_rails
require "rails"
require "action_controller/railtie"
class MyApp < Rails::Application
config.action_controller.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" }
end
MyApp.initialize!
class ::ApplicationController < ActionController::Base
end
class ::OmgController < ::ApplicationController
def index
render :text => omg_path
end
end
MyApp.routes.draw do
match "/" => "omg#index", :as => :omg
end
require 'rack/test'
extend Rack::Test::Methods
get "/"
assert_equal "/", last_response.body
end
end
end