Constants set in the development/test/production environment file are set in Object

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2711 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jamis Buck 2005-10-23 13:39:24 +00:00
parent 3ab3a70b7c
commit cdd49c5360
4 changed files with 43 additions and 0 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Constants set in the development/test/production environment file are set in Object
* Scaffold generator pays attention to the controller name. #2562 [self@mattmower.com]
* Include tasks from vendor/plugins/*/tasks in the Rakefile #2545 [Rick Olson]

View File

@ -146,7 +146,11 @@ module Rails
def load_environment
silence_warnings do
config = configuration
constants = self.class.constants
eval(IO.read(configuration.environment_path), binding)
(self.class.constants - constants).each do |const|
Object.const_set(const, self.class.const_get(const))
end
end
end

View File

@ -0,0 +1 @@
SET_FROM_ENV = "success"

View File

@ -0,0 +1,36 @@
$:.unshift File.dirname(__FILE__) + "/../lib"
$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib"
require 'test/unit'
require 'active_support'
require 'initializer'
class InitializerTest < Test::Unit::TestCase
class ConfigurationMock < Rails::Configuration
def initialize(envpath)
super()
@envpath = envpath
end
def environment_path
@envpath
end
end
def setup
Object.const_set(:RAILS_ROOT, "") rescue nil
end
def teardown
Object.remove_const(:RAILS_ROOT) rescue nil
end
def test_load_environment_with_constant
config = ConfigurationMock.new("#{File.dirname(__FILE__)}/fixtures/environment_with_constant.rb")
Rails::Initializer.run(:load_environment, config)
assert Object.const_defined?(:SET_FROM_ENV)
assert_equal "success", SET_FROM_ENV
ensure
Object.remove_const(:SET_FROM_ENV) rescue nil
end
end