diff options
-rw-r--r-- | railties/lib/rails.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/application.rb | 4 | ||||
-rw-r--r-- | railties/test/engine_test.rb | 10 |
3 files changed, 18 insertions, 4 deletions
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index ecd8c22dd8..e7172e491f 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -29,7 +29,13 @@ module Rails autoload :WelcomeController class << self - attr_accessor :application, :cache, :logger + @application = @app_class = nil + + attr_writer :application + attr_accessor :app_class, :cache, :logger + def application + @application ||= (app_class.instance if app_class) + end delegate :initialize!, :initialized?, to: :application diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index c5fd08e743..292986b475 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -87,7 +87,7 @@ module Rails class << self def inherited(base) super - base.instance + Rails.app_class = base end # Makes the +new+ method public. @@ -117,8 +117,6 @@ module Rails @railties = nil @message_verifiers = {} - Rails.application ||= self - add_lib_to_load_path! ActiveSupport.run_load_hooks(:before_configuration, self) diff --git a/railties/test/engine_test.rb b/railties/test/engine_test.rb index 7970913d21..8401494bd2 100644 --- a/railties/test/engine_test.rb +++ b/railties/test/engine_test.rb @@ -11,4 +11,14 @@ class EngineTest < ActiveSupport::TestCase assert !engine.routes? end + + def test_application_can_be_subclassed + klass = Class.new(Rails::Application) do + attr_reader :hello + def initialize + @hello = "world" + end + end + assert_equal "world", klass.instance.hello + end end |