Permalink
Browse files

Ensure routes are loaded only after the initialization process finish…

…es, ensuring all configuration options were applied.
  • Loading branch information...
1 parent 3e931b1 commit 20866a5c952ec84f9ba521a9f9583385f561ecbd @josevalim josevalim committed Sep 2, 2010
@@ -8,10 +8,5 @@ class Railtie < Rails::Railtie
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 Finisher
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 @@ def baz
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|

0 comments on commit 20866a5

Please sign in to comment.