diff options
author | Carl Lerche <carllerche@mac.com> | 2009-10-08 15:08:08 -0700 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2009-10-08 15:08:08 -0700 |
commit | ed77e84c4b00bf1d2269af6a07575c30039d942d (patch) | |
tree | 44d021dc0e40382458b4829e3c76b697b9e1aaf7 /railties | |
parent | 7faa52a424a7a9edea796babf6d091930df5396a (diff) | |
download | rails-ed77e84c4b00bf1d2269af6a07575c30039d942d.tar.gz rails-ed77e84c4b00bf1d2269af6a07575c30039d942d.tar.bz2 rails-ed77e84c4b00bf1d2269af6a07575c30039d942d.zip |
Ported over more initializers
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application.rb | 42 | ||||
-rw-r--r-- | railties/lib/rails/initializer.rb | 42 | ||||
-rw-r--r-- | railties/test/application/initializer_test.rb | 7 | ||||
-rw-r--r-- | railties/test/initializer_test.rb | 11 |
4 files changed, 48 insertions, 54 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index c7b92ef9b7..5b5f6842b9 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -102,7 +102,47 @@ module Rails # Create tmp directories initializer :ensure_tmp_directories_exist do %w(cache pids sessions sockets).each do |dir_to_make| - FileUtils.mkdir_p(File.join(configuration.root_path, 'tmp', dir_to_make)) + FileUtils.mkdir_p(File.join(config.root_path, 'tmp', dir_to_make)) + end + end + + # Loads the environment specified by Configuration#environment_path, which + # is typically one of development, test, or production. + initializer :load_environment do + silence_warnings do + next if @environment_loaded + next unless File.file?(config.environment_path) + + @environment_loaded = true + constants = self.class.constants + + eval(IO.read(configuration.environment_path), binding, configuration.environment_path) + + (self.class.constants - constants).each do |const| + Object.const_set(const, self.class.const_get(const)) + end + end + end + + initializer :add_gem_load_paths do + require 'rails/gem_dependency' + Rails::GemDependency.add_frozen_gem_path + unless config.gems.empty? + require "rubygems" + config.gems.each { |gem| gem.add_load_paths } + end + end + + # Preload all frameworks specified by the Configuration#frameworks. + # Used by Passenger to ensure everything's loaded before forking and + # to avoid autoload race conditions in JRuby. + initializer :preload_frameworks do + if config.preload_frameworks + config.frameworks.each do |framework| + # String#classify and #constantize aren't available yet. + toplevel = Object.const_get(framework.to_s.gsub(/(?:^|_)(.)/) { $1.upcase }) + toplevel.load_all! if toplevel.respond_to?(:load_all!) + end end end end diff --git a/railties/lib/rails/initializer.rb b/railties/lib/rails/initializer.rb index 687455feca..bfdecd0f80 100644 --- a/railties/lib/rails/initializer.rb +++ b/railties/lib/rails/initializer.rb @@ -116,48 +116,6 @@ module Rails end end - # Loads the environment specified by Configuration#environment_path, which - # is typically one of development, test, or production. - Initializer.default.add :load_environment do - silence_warnings do - next if @environment_loaded - next unless File.file?(configuration.environment_path) - - @environment_loaded = true - - config = configuration - constants = self.class.constants - - eval(IO.read(configuration.environment_path), binding, configuration.environment_path) - - (self.class.constants - constants).each do |const| - Object.const_set(const, self.class.const_get(const)) - end - end - end - - Initializer.default.add :add_gem_load_paths do - require 'rails/gem_dependency' - Rails::GemDependency.add_frozen_gem_path - unless config.gems.empty? - require "rubygems" - config.gems.each { |gem| gem.add_load_paths } - end - end - - # Preload all frameworks specified by the Configuration#frameworks. - # Used by Passenger to ensure everything's loaded before forking and - # to avoid autoload race conditions in JRuby. - Initializer.default.add :preload_frameworks do - if configuration.preload_frameworks - configuration.frameworks.each do |framework| - # String#classify and #constantize aren't available yet. - toplevel = Object.const_get(framework.to_s.gsub(/(?:^|_)(.)/) { $1.upcase }) - toplevel.load_all! if toplevel.respond_to?(:load_all!) - end - end - end - # This initialization routine does nothing unless <tt>:active_record</tt> # is one of the frameworks to load (Configuration#frameworks). If it is, # this sets the database configuration from Configuration#database_configuration diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 1b6af718c0..6de07b4122 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -54,5 +54,12 @@ module ApplicationTests assert Zoo end + + test "load environment with global" do + app_file "config/environments/development.rb", "$initialize_test_set_from_env = 'success'" + assert_nil $initialize_test_set_from_env + Rails::Initializer.run { } + assert_equal "success", $initialize_test_set_from_env + end end end
\ No newline at end of file diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 616374b183..219c65e637 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -33,17 +33,6 @@ class ConfigurationMock < Rails::Configuration end end -class Initializer_load_environment_Test < Test::Unit::TestCase - def test_load_environment_with_constant - config = ConfigurationMock.new("#{File.dirname(__FILE__)}/fixtures/environment_with_constant.rb") - assert_nil $initialize_test_set_from_env - Rails::Initializer.run(:load_environment, config) - assert_equal "success", $initialize_test_set_from_env - ensure - $initialize_test_set_from_env = nil - end -end - class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::TestCase def setup config = ConfigurationMock.new("") |