Skip to content

Commit

Permalink
Initializer to sort files before eager loading. [#859 state:resolved]
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tomafro authored and lifo committed Aug 22, 2008
1 parent 683ff23 commit 89d1c77
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion railties/lib/initializer.rb
Expand Up @@ -356,7 +356,7 @@ def load_application_classes
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
Expand Down
3 changes: 3 additions & 0 deletions railties/test/fixtures/eager/zoo.rb
@@ -0,0 +1,3 @@
class Zoo
include ReptileHouse
end
2 changes: 2 additions & 0 deletions railties/test/fixtures/eager/zoo/reptile_house.rb
@@ -0,0 +1,2 @@
module Zoo::ReptileHouse
end
18 changes: 18 additions & 0 deletions railties/test/initializer_test.rb
Expand Up @@ -30,6 +30,24 @@ def test_load_environment_with_constant

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
Expand Down

0 comments on commit 89d1c77

Please sign in to comment.