提交 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
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 Finisher
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)
......
......@@ -52,6 +52,14 @@ def after_initialize(&blk)
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
......
......@@ -12,6 +12,10 @@ def copy_app
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 @@ def setup
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册