Add config.to_prepare back and add tests for it.
Signed-off-by: Carl Lerche <carllerche@mac.com>
This commit is contained in:
parent
226d8e745a
commit
d3d487479a
|
@ -15,6 +15,12 @@ module Rails
|
||||||
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 Rails
|
||||||
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 @@ module Rails
|
||||||
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 @@ module ApplicationTests
|
||||||
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 @@ module ApplicationTests
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue