mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Ensure routes are loaded only after the initialization process finishes, ensuring all configuration options were applied.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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|
|
||||
|
||||
Reference in New Issue
Block a user