1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Load config/preinitializer.rb, if present, before loading the environment. Closes #9943.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8159 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2007-11-17 01:38:58 +00:00
parent 24c9250968
commit 4249ffe249
3 changed files with 32 additions and 2 deletions

View file

@ -1,5 +1,7 @@
*SVN* *SVN*
* Load config/preinitializer.rb, if present, before loading the environment. #9943 [Chad Woolley]
* FastCGI handler ignores unsupported signals like USR2 on Windows. [Grzegorz Derebecki] * FastCGI handler ignores unsupported signals like USR2 on Windows. [Grzegorz Derebecki]
* Only load ActionMailer::TestCase if ActionMailer is loaded. Closes #10137 [defunkt] * Only load ActionMailer::TestCase if ActionMailer is loaded. Closes #10137 [defunkt]

View file

@ -6,7 +6,10 @@ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
module Rails module Rails
class << self class << self
def boot! def boot!
pick_boot.run unless booted? unless booted?
preinitialize
pick_boot.run
end
end end
def booted? def booted?
@ -20,6 +23,14 @@ module Rails
def vendor_rails? def vendor_rails?
File.exist?("#{RAILS_ROOT}/vendor/rails") File.exist?("#{RAILS_ROOT}/vendor/rails")
end end
def preinitialize
load(preinitializer_path) if File.exists?(preinitializer_path)
end
def preinitializer_path
"#{RAILS_ROOT}/config/preinitializer.rb"
end
end end
class Boot class Boot

View file

@ -11,12 +11,29 @@ class BootTest < Test::Unit::TestCase
assert_nil Rails.boot! assert_nil Rails.boot!
end end
def test_boot_picks_and_runs_if_not_booted def test_boot_preinitializes_then_picks_and_runs_if_not_booted
Rails.expects(:booted?).returns(false) Rails.expects(:booted?).returns(false)
Rails.expects(:preinitialize)
Rails.expects(:pick_boot).returns(mock(:run => 'result')) Rails.expects(:pick_boot).returns(mock(:run => 'result'))
assert_equal 'result', Rails.boot! assert_equal 'result', Rails.boot!
end end
def test_preinitialize_does_not_raise_exception_if_preinitializer_file_does_not_exist
Rails.stubs(:preinitializer_path).returns('/there/is/no/such/file')
assert_nothing_raised { Rails.preinitialize }
end
def test_load_preinitializer_loads_preinitializer_file
Rails.stubs(:preinitializer_path).returns("#{File.dirname(__FILE__)}/fixtures/environment_with_constant.rb")
assert_nil $initialize_test_set_from_env
Rails.preinitialize
assert_equal "success", $initialize_test_set_from_env
ensure
$initialize_test_set_from_env = nil
end
def test_boot_vendor_rails_by_default def test_boot_vendor_rails_by_default
Rails.expects(:booted?).returns(false) Rails.expects(:booted?).returns(false)
File.expects(:exist?).with("#{RAILS_ROOT}/vendor/rails").returns(true) File.expects(:exist?).with("#{RAILS_ROOT}/vendor/rails").returns(true)