diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/configuration.rb | 8 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 23 |
3 files changed, 38 insertions, 1 deletions
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index c0b16a0090..b722679ec2 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -15,6 +15,12 @@ module Rails end end + initializer :add_to_prepare_blocks do + config.to_prepare_blocks.each do |block| + ActionDispatch::Callbacks.to_prepare(&block) + end + end + initializer :add_builtin_route do |app| if Rails.env.development? app.routes_reloader.paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') @@ -25,7 +31,7 @@ module Rails app end - # Fires the user-supplied after_initialize block (config#after_initialize) + # Fires the user-supplied after_initialize block (config.after_initialize) initializer :after_initialize do config.after_initialize_blocks.each do |block| block.call(self) diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 6d5fa87439..a95075562f 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -52,6 +52,14 @@ module Rails after_initialize_blocks << blk if blk end + def to_prepare_blocks + @@to_prepare_blocks ||= [] + end + + def to_prepare(&blk) + to_prepare_blocks << blk if blk + end + def respond_to?(name) super || name.to_s =~ config_key_regexp end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 666c47af67..50d6ba2855 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -12,6 +12,10 @@ module ApplicationTests FileUtils.cp_r(app_path, new_app) end + def app + @app ||= Rails.application + end + def setup FileUtils.rm_rf(new_app) if File.directory?(new_app) build_app @@ -132,5 +136,24 @@ module ApplicationTests require "#{app_path}/config/application" end end + + test "config.to_prepare is forwarded to ActionDispatch" do + $prepared = false + + add_to_config <<-RUBY + config.to_prepare do + $prepared = true + end + RUBY + + assert !$prepared + + require "#{app_path}/config/environment" + require 'rack/test' + extend Rack::Test::Methods + + get "/" + assert $prepared + end end end |