Rails.application should be set inside before_configuration hook

Fixes #14620
上级 70c83f49
......@@ -87,7 +87,7 @@ class Application < Engine
class << self
def inherited(base)
super
Rails.application ||= base.instance
base.instance
end
# Makes the +new+ method public.
......@@ -117,6 +117,8 @@ def initialize(initial_variable_values = {}, &block)
@railties = nil
@message_verifiers = {}
Rails.application ||= self
add_lib_to_load_path!
ActiveSupport.run_load_hooks(:before_configuration, self)
......
......@@ -21,6 +21,12 @@ def test_cloning_an_application_makes_a_shallow_copy_of_config
assert_equal Rails.application.config.secret_key_base, clone.config.secret_key_base, "The base secret key on the config should be the same"
end
def test_inheriting_multiple_times_from_application
new_application_class = Class.new(Rails::Application)
assert_not_equal Rails.application.object_id, new_application_class.instance.object_id
end
def test_initialization_of_multiple_copies_of_same_application
application1 = AppTemplate::Application.new
application2 = AppTemplate::Application.new
......
......@@ -72,6 +72,14 @@ class Foo < Rails::Railtie ; config.to_prepare { $to_prepare = true } ; end
assert $to_prepare
end
test "railtie have access to application in before_configuration callbacks" do
$after_initialize = false
class Foo < Rails::Railtie ; config.before_configuration { $before_configuration = Rails.root.to_path } ; end
assert_not $before_configuration
require "#{app_path}/config/environment"
assert_equal app_path, $before_configuration
end
test "railtie can add after_initialize callbacks" do
$after_initialize = false
class Foo < Rails::Railtie ; config.after_initialize { $after_initialize = true } ; end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册