mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Expose remaining hooks to minimize the need for a Railtie based on feedback from plugin developers.
This commit is contained in:
@@ -69,7 +69,6 @@ module Rails
|
||||
raise "You cannot have more than one Rails::Application" if Rails.application
|
||||
super
|
||||
Rails.application = base.instance
|
||||
|
||||
ActiveSupport.run_load_hooks(:before_configuration, base.instance)
|
||||
end
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ module Rails
|
||||
|
||||
initializer :eager_load! do
|
||||
if config.cache_classes && !$rails_rake_task
|
||||
ActiveSupport.run_load_hooks(:before_eager_load, self)
|
||||
railties.all(&:eager_load!)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -68,6 +68,18 @@ module Rails
|
||||
end
|
||||
end
|
||||
|
||||
def before_configuration(&block)
|
||||
ActiveSupport.on_load(:before_configuration, :yield => true, &block)
|
||||
end
|
||||
|
||||
def before_eager_load(&block)
|
||||
ActiveSupport.on_load(:before_eager_load, :yield => true, &block)
|
||||
end
|
||||
|
||||
def before_initialize(&block)
|
||||
ActiveSupport.on_load(:before_initialize, :yield => true, &block)
|
||||
end
|
||||
|
||||
def after_initialize(&block)
|
||||
ActiveSupport.on_load(:after_initialize, :yield => true, &block)
|
||||
end
|
||||
|
||||
@@ -16,16 +16,34 @@ module ApplicationTests
|
||||
assert $foo
|
||||
end
|
||||
|
||||
test "after_initialize block works correctly" do
|
||||
test "hooks block works correctly without cache classes (before_eager_load is not called)" do
|
||||
add_to_config <<-RUBY
|
||||
$initialization_callbacks = []
|
||||
config.root = "#{app_path}"
|
||||
config.after_initialize { $test_after_initialize_block1 = "success" }
|
||||
config.after_initialize { $test_after_initialize_block2 = "congratulations" }
|
||||
config.cache_classes = false
|
||||
config.before_configuration { $initialization_callbacks << 1 }
|
||||
config.before_initialize { $initialization_callbacks << 2 }
|
||||
config.before_eager_load { Boom }
|
||||
config.after_initialize { $initialization_callbacks << 3 }
|
||||
RUBY
|
||||
require "#{app_path}/config/environment"
|
||||
|
||||
assert_equal "success", $test_after_initialize_block1
|
||||
assert_equal "congratulations", $test_after_initialize_block2
|
||||
require "#{app_path}/config/environment"
|
||||
assert_equal [1,2,3], $initialization_callbacks
|
||||
end
|
||||
|
||||
test "hooks block works correctly with cache classes" do
|
||||
add_to_config <<-RUBY
|
||||
$initialization_callbacks = []
|
||||
config.root = "#{app_path}"
|
||||
config.cache_classes = true
|
||||
config.before_configuration { $initialization_callbacks << 1 }
|
||||
config.before_initialize { $initialization_callbacks << 2 }
|
||||
config.before_eager_load { $initialization_callbacks << 3 }
|
||||
config.after_initialize { $initialization_callbacks << 4 }
|
||||
RUBY
|
||||
|
||||
require "#{app_path}/config/environment"
|
||||
assert_equal [1,2,3,4], $initialization_callbacks
|
||||
end
|
||||
|
||||
test "after_initialize runs after frameworks have been initialized" do
|
||||
Reference in New Issue
Block a user