提交 d3d48747 编写于 作者: J José Valim 提交者: Carl Lerche

Add config.to_prepare back and add tests for it.

Signed-off-by: NCarl Lerche <carllerche@mac.com>
上级 226d8e74
...@@ -15,6 +15,12 @@ module Finisher ...@@ -15,6 +15,12 @@ module Finisher
end end
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| initializer :add_builtin_route do |app|
if Rails.env.development? if Rails.env.development?
app.routes_reloader.paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') app.routes_reloader.paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb')
...@@ -25,7 +31,7 @@ module Finisher ...@@ -25,7 +31,7 @@ module Finisher
app app
end 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 initializer :after_initialize do
config.after_initialize_blocks.each do |block| config.after_initialize_blocks.each do |block|
block.call(self) block.call(self)
......
...@@ -52,6 +52,14 @@ def after_initialize(&blk) ...@@ -52,6 +52,14 @@ def after_initialize(&blk)
after_initialize_blocks << blk if blk after_initialize_blocks << blk if blk
end end
def to_prepare_blocks
@@to_prepare_blocks ||= []
end
def to_prepare(&blk)
to_prepare_blocks << blk if blk
end
def respond_to?(name) def respond_to?(name)
super || name.to_s =~ config_key_regexp super || name.to_s =~ config_key_regexp
end end
......
...@@ -12,6 +12,10 @@ def copy_app ...@@ -12,6 +12,10 @@ def copy_app
FileUtils.cp_r(app_path, new_app) FileUtils.cp_r(app_path, new_app)
end end
def app
@app ||= Rails.application
end
def setup def setup
FileUtils.rm_rf(new_app) if File.directory?(new_app) FileUtils.rm_rf(new_app) if File.directory?(new_app)
build_app build_app
...@@ -132,5 +136,24 @@ def setup ...@@ -132,5 +136,24 @@ def setup
require "#{app_path}/config/application" require "#{app_path}/config/application"
end end
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
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册