diff options
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rw-r--r-- | railties/lib/initializer.rb | 4 | ||||
-rw-r--r-- | railties/test/fixtures/environment_with_constant.rb | 1 | ||||
-rw-r--r-- | railties/test/initializer_test.rb | 36 |
4 files changed, 43 insertions, 0 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 8c7a073f68..86e318a8b5 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -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] diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 2d72b55b8b..350930bb15 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -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 diff --git a/railties/test/fixtures/environment_with_constant.rb b/railties/test/fixtures/environment_with_constant.rb new file mode 100644 index 0000000000..96efe9c23a --- /dev/null +++ b/railties/test/fixtures/environment_with_constant.rb @@ -0,0 +1 @@ +SET_FROM_ENV = "success"
\ No newline at end of file diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb new file mode 100644 index 0000000000..4c25ad8a0a --- /dev/null +++ b/railties/test/initializer_test.rb @@ -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
\ No newline at end of file |