mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Revert behavior from a5684dfa3c
and ensure after_initializer is executed after to_prepare callbacks.
This commit is contained in:
parent
e2806929ec
commit
e49f94d71c
3 changed files with 20 additions and 11 deletions
|
@ -37,7 +37,7 @@ module ActionDispatch
|
|||
|
||||
def initialize(app, prepare_each_request = false)
|
||||
@app, @prepare_each_request = app, prepare_each_request
|
||||
run_callbacks(:prepare) unless @prepare_each_request
|
||||
run_callbacks(:prepare)
|
||||
end
|
||||
|
||||
def call(env)
|
||||
|
|
|
@ -27,19 +27,16 @@ module Rails
|
|||
end
|
||||
end
|
||||
|
||||
# Fires the user-supplied after_initialize block (config.after_initialize)
|
||||
# Should run before the middleware stack is built, because building the
|
||||
# middleware already fires to_prepare callbacks in test and production.
|
||||
initializer :build_middleware_stack do
|
||||
app
|
||||
end
|
||||
|
||||
initializer :after_initialize do
|
||||
config.after_initialize_blocks.each do |block|
|
||||
block.call(self)
|
||||
end
|
||||
end
|
||||
|
||||
initializer :build_middleware_stack do
|
||||
app
|
||||
end
|
||||
|
||||
# Disable dependency loading during request cycle
|
||||
initializer :disable_dependency_loading do
|
||||
if config.cache_classes && !config.dependency_loading
|
||||
|
|
|
@ -52,9 +52,22 @@ module ApplicationTests
|
|||
assert $activerecord_configurations['development']
|
||||
end
|
||||
|
||||
test "after_initialize happens before to_prepare (i.e. before the middleware stack is built) on production" do
|
||||
test "after_initialize happens after to_prepare in development" do
|
||||
$order = []
|
||||
add_to_config <<-RUBY
|
||||
config.cache_classes = false
|
||||
config.after_initialize { $order << :after_initialize }
|
||||
config.to_prepare { $order << :to_prepare }
|
||||
RUBY
|
||||
|
||||
require "#{app_path}/config/environment"
|
||||
assert [:to_prepare, :after_initialize], $order
|
||||
end
|
||||
|
||||
test "after_initialize happens after to_prepare in production" do
|
||||
$order = []
|
||||
add_to_config <<-RUBY
|
||||
config.cache_classes = true
|
||||
config.after_initialize { $order << :after_initialize }
|
||||
config.to_prepare { $order << :to_prepare }
|
||||
RUBY
|
||||
|
@ -62,8 +75,7 @@ module ApplicationTests
|
|||
require "#{app_path}/config/application"
|
||||
Rails.env.replace "production"
|
||||
require "#{app_path}/config/environment"
|
||||
assert [:after_initialize, :to_prepare], $order
|
||||
assert [:to_prepare, :after_initialize], $order
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue