mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure config.after_initializer is executed before building the middleware stack.
This commit is contained in:
parent
1477a6101d
commit
a5684dfa3c
3 changed files with 21 additions and 4 deletions
|
@ -27,17 +27,19 @@ module Rails
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
initializer :build_middleware_stack do
|
|
||||||
app
|
|
||||||
end
|
|
||||||
|
|
||||||
# Fires the user-supplied after_initialize block (config.after_initialize)
|
# 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 :after_initialize do
|
initializer :after_initialize do
|
||||||
config.after_initialize_blocks.each do |block|
|
config.after_initialize_blocks.each do |block|
|
||||||
block.call(self)
|
block.call(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
initializer :build_middleware_stack do
|
||||||
|
app
|
||||||
|
end
|
||||||
|
|
||||||
# Disable dependency loading during request cycle
|
# Disable dependency loading during request cycle
|
||||||
initializer :disable_dependency_loading do
|
initializer :disable_dependency_loading do
|
||||||
if config.cache_classes && !config.dependency_loading
|
if config.cache_classes && !config.dependency_loading
|
||||||
|
|
|
@ -15,6 +15,7 @@ module Rails
|
||||||
def inherited(base)
|
def inherited(base)
|
||||||
unless abstract_railtie?(base)
|
unless abstract_railtie?(base)
|
||||||
base.called_from = begin
|
base.called_from = begin
|
||||||
|
# Remove the line number from backtraces making sure we don't leave anything behind
|
||||||
call_stack = caller.map { |p| p.split(':')[0..-2].join(':') }
|
call_stack = caller.map { |p| p.split(':')[0..-2].join(':') }
|
||||||
File.dirname(call_stack.detect { |p| p !~ %r[railties[\w\-]*/lib/rails|rack[\w\-]*/lib/rack] })
|
File.dirname(call_stack.detect { |p| p !~ %r[railties[\w\-]*/lib/rails|rack[\w\-]*/lib/rack] })
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,5 +51,19 @@ module ApplicationTests
|
||||||
assert $activerecord_configurations
|
assert $activerecord_configurations
|
||||||
assert $activerecord_configurations['development']
|
assert $activerecord_configurations['development']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "after_initialize happens before to_prepare (i.e. before the middleware stack is built) on production" do
|
||||||
|
$order = []
|
||||||
|
add_to_config <<-RUBY
|
||||||
|
config.after_initialize { $order << :after_initialize }
|
||||||
|
config.to_prepare { $order << :to_prepare }
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
require "#{app_path}/config/application"
|
||||||
|
Rails.env.replace "production"
|
||||||
|
require "#{app_path}/config/environment"
|
||||||
|
assert [:after_initialize, :to_prepare], $order
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue