From db99324a89a2a681c6f6b0957dac7a309bfca574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 26 Jan 2010 12:14:48 +0100 Subject: Ensure calling a method in Rails::Application does not instantiate a void application. --- railties/lib/rails/application.rb | 6 +++--- railties/test/application/configuration_test.rb | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index b7e5eb7a1d..eba49e1520 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -16,10 +16,10 @@ module Rails alias :configure :class_eval def instance - if instance_of?(Rails::Application) - Rails.application.instance + if self == Rails::Application + Rails.application else - @instance ||= new + @@instance ||= new end end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 6968e87986..d3ba54a668 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -19,6 +19,13 @@ module ApplicationTests FileUtils.rm_rf("#{app_path}/config/environments") end + test "Rails::Application.instance is nil until app is initialized" do + require 'rails' + assert_nil Rails::Application.instance + require "#{app_path}/config/environment" + assert_equal AppTemplate::Application.instance, Rails::Application.instance + end + test "the application root is set correctly" do require "#{app_path}/config/environment" assert_equal Pathname.new(app_path), Rails.application.root -- cgit v1.2.3