mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Initializer to sort files before eager loading. [#859 state:resolved]
Changed Rails::Initializer to sort files before eager loading them. This ensures that any files in a parent directory will be loaded before files in a subdirectory of the 'same' name. i.e. zoo.rb will be loaded before zoo/reptile_house.rb Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
parent
683ff235e6
commit
89d1c77dd0
4 changed files with 24 additions and 1 deletions
|
@ -356,7 +356,7 @@ Run `rake gems:install` to install the missing gems.
|
|||
if configuration.cache_classes
|
||||
configuration.eager_load_paths.each do |load_path|
|
||||
matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
|
||||
Dir.glob("#{load_path}/**/*.rb").each do |file|
|
||||
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
|
||||
require_dependency file.sub(matcher, '\1')
|
||||
end
|
||||
end
|
||||
|
|
3
railties/test/fixtures/eager/zoo.rb
vendored
Normal file
3
railties/test/fixtures/eager/zoo.rb
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
class Zoo
|
||||
include ReptileHouse
|
||||
end
|
2
railties/test/fixtures/eager/zoo/reptile_house.rb
vendored
Normal file
2
railties/test/fixtures/eager/zoo/reptile_house.rb
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
module Zoo::ReptileHouse
|
||||
end
|
|
@ -30,6 +30,24 @@ class Initializer_load_environment_Test < Test::Unit::TestCase
|
|||
|
||||
end
|
||||
|
||||
class Initializer_eager_loading_Test < Test::Unit::TestCase
|
||||
def setup
|
||||
@config = ConfigurationMock.new("")
|
||||
@config.cache_classes = true
|
||||
@config.load_paths = [File.expand_path(File.dirname(__FILE__) + "/fixtures/eager")]
|
||||
@config.eager_load_paths = [File.expand_path(File.dirname(__FILE__) + "/fixtures/eager")]
|
||||
@initializer = Rails::Initializer.new(@config)
|
||||
@initializer.set_load_path
|
||||
@initializer.set_autoload_paths
|
||||
end
|
||||
|
||||
def test_eager_loading_loads_parent_classes_before_children
|
||||
assert_nothing_raised do
|
||||
@initializer.load_application_classes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
uses_mocha 'Initializer after_initialize' do
|
||||
class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::TestCase
|
||||
def setup
|
||||
|
|
Loading…
Reference in a new issue