Permalink
Browse files

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
  • Loading branch information...
1 parent 3ab3a70 commit cdd49c53607020890997a2d7a95621b512425b65 @jamis jamis committed Oct 23, 2005
View
@@ -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]
@@ -146,7 +146,11 @@ def load_plugins
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
@@ -0,0 +1 @@
+SET_FROM_ENV = "success"
@@ -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

0 comments on commit cdd49c5

Please sign in to comment.