diff options
author | José Valim <jose.valim@gmail.com> | 2010-09-02 12:54:16 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-09-02 12:54:21 +0200 |
commit | 48bf667a8b1c489bd6edff0b8322324a7a1b06bc (patch) | |
tree | 0abae7b918253749988d4e575b31e405e41dfac7 /railties | |
parent | 38a421b34d0b414564e919f67d339fac067a56e6 (diff) | |
download | rails-48bf667a8b1c489bd6edff0b8322324a7a1b06bc.tar.gz rails-48bf667a8b1c489bd6edff0b8322324a7a1b06bc.tar.bz2 rails-48bf667a8b1c489bd6edff0b8322324a7a1b06bc.zip |
Ensure routes are loaded only after the initialization process finishes, ensuring all configuration options were applied.
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 7 | ||||
-rw-r--r-- | railties/test/application/routing_test.rb | 17 |
2 files changed, 24 insertions, 0 deletions
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 855467227b..8fd2aa0bce 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -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 diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index febc53bac9..53bb7868da 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -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| |