Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rails.application should be set inside before_configuration hook

Fixes #14620
  • Loading branch information...
commit 32896e5b1be4daf3ac27bc9e555609f32868c8f0 1 parent 9b92c6c
@rafaelfranca rafaelfranca authored
View
4 railties/lib/rails/application.rb
@@ -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)
View
6 railties/test/application/multiple_applications_test.rb
@@ -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
View
8 railties/test/railties/railtie_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.