Ensure routes are loaded only after the initialization process finishes, ensuring all configuration options were applied.

This commit is contained in:
José Valim
2010-09-02 12:54:16 +02:00
parent 38a421b34d
commit 48bf667a8b
3 changed files with 24 additions and 5 deletions

View File

@@ -8,10 +8,5 @@ module ActionDispatch
config.action_dispatch.ip_spoofing_check = true
config.action_dispatch.show_exceptions = true
config.action_dispatch.best_standards_support = true
# Prepare dispatcher callbacks and run 'prepare' callbacks
initializer "action_dispatch.prepare_dispatcher" do |app|
ActionDispatch::Callbacks.to_prepare { app.routes_reloader.execute_if_updated }
end
end
end

View File

@@ -46,6 +46,13 @@ module Rails
ActiveSupport.run_load_hooks(:after_initialize, self)
end
# Force routes to be loaded just at the end and add it to to_prepare callbacks
initializer :set_routes_reloader do |app|
reloader = lambda { app.routes_reloader.execute_if_updated }
reloader.call
ActionDispatch::Callbacks.to_prepare(&reloader)
end
# Disable dependency loading during request cycle
initializer :disable_dependency_loading do
if config.cache_classes && !config.dependency_loading

View File

@@ -215,6 +215,23 @@ module ApplicationTests
end
end
test 'routes are loaded just after initialization' do
require "#{app_path}/config/application"
ActiveSupport.on_load(:after_initialize) do
::InitializeRackApp = lambda { |env| [200, {}, ["InitializeRackApp"]] }
end
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do |map|
match 'foo', :to => ::InitializeRackApp
end
RUBY
get '/foo'
assert_equal "InitializeRackApp", last_response.body
end
test 'resource routing with irrigular inflection' do
app_file 'config/initializers/inflection.rb', <<-RUBY
ActiveSupport::Inflector.inflections do |inflect|