Permalink
Browse files

Rails.application should be set inside before_configuration hook

Fixes #14620
  • Loading branch information...
1 parent 70c83f4 commit e1404ec824d263d25717468c6f4b73ee7b2bdf4c @rafaelfranca rafaelfranca committed Apr 7, 2014
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

0 comments on commit e1404ec

Please sign in to comment.