diff options
author | Tom Ward <tom@popdog.net> | 2008-08-19 13:19:41 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-08-22 13:06:34 +0100 |
commit | 89d1c77dd012f087c091e0f23874c582ea4e3703 (patch) | |
tree | 94732218057b59da6eff36a7fadbfada9248c816 /railties | |
parent | 683ff235e6b81d28962f5a71ff53730a1c118fc8 (diff) | |
download | rails-89d1c77dd012f087c091e0f23874c582ea4e3703.tar.gz rails-89d1c77dd012f087c091e0f23874c582ea4e3703.tar.bz2 rails-89d1c77dd012f087c091e0f23874c582ea4e3703.zip |
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>
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/initializer.rb | 2 | ||||
-rw-r--r-- | railties/test/fixtures/eager/zoo.rb | 3 | ||||
-rw-r--r-- | railties/test/fixtures/eager/zoo/reptile_house.rb | 2 | ||||
-rw-r--r-- | railties/test/initializer_test.rb | 18 |
4 files changed, 24 insertions, 1 deletions
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 70c6a629ec..ee847e5561 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -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 diff --git a/railties/test/fixtures/eager/zoo.rb b/railties/test/fixtures/eager/zoo.rb new file mode 100644 index 0000000000..8b10ef984b --- /dev/null +++ b/railties/test/fixtures/eager/zoo.rb @@ -0,0 +1,3 @@ +class Zoo + include ReptileHouse +end
\ No newline at end of file diff --git a/railties/test/fixtures/eager/zoo/reptile_house.rb b/railties/test/fixtures/eager/zoo/reptile_house.rb new file mode 100644 index 0000000000..82bbafce79 --- /dev/null +++ b/railties/test/fixtures/eager/zoo/reptile_house.rb @@ -0,0 +1,2 @@ +module Zoo::ReptileHouse +end
\ No newline at end of file diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 07303a510e..5147eeb482 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -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 |