diff options
author | Jonathan del Strother <jon.delStrother@audioboo.fm> | 2011-08-24 17:30:50 +0100 |
---|---|---|
committer | Jonathan del Strother <jon.delStrother@audioboo.fm> | 2011-08-24 18:14:25 +0100 |
commit | e0714ee005a366aa92449fc4f92cf97aa8e2f349 (patch) | |
tree | aa4df7b0395e95602561faff609a1a80d127704d /activesupport | |
parent | 976b2be1085aa22f84c6fcbe40ba25ba4f89051c (diff) | |
download | rails-e0714ee005a366aa92449fc4f92cf97aa8e2f349.tar.gz rails-e0714ee005a366aa92449fc4f92cf97aa8e2f349.tar.bz2 rails-e0714ee005a366aa92449fc4f92cf97aa8e2f349.zip |
Fix autoload_once_paths when using Pathnames & ruby 1.9
Under ruby 1.9.2 -
"/var/log".starts_with?(Pathname.new("/var")) # => false
so setting config.autoload_once_paths with Pathnames would not work
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/dependencies.rb | 3 | ||||
-rw-r--r-- | activesupport/test/dependencies_test.rb | 18 |
2 files changed, 20 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 6252e7f7c3..c072a8e646 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -421,7 +421,8 @@ module ActiveSupport #:nodoc: end def load_once_path?(path) - autoload_once_paths.any? { |base| path.starts_with? base } + # to_s works around a ruby1.9 issue where #starts_with?(Pathname) will always return false + autoload_once_paths.any? { |base| path.starts_with? base.to_s } end # Attempt to autoload the provided module name by searching for a directory diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index b0e96731cc..fe8f51e11a 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -520,6 +520,24 @@ class DependenciesTest < Test::Unit::TestCase ActiveSupport::Dependencies.autoload_once_paths = [] end + def test_autoload_once_pathnames_do_not_add_to_autoloaded_constants + with_autoloading_fixtures do + pathnames = ActiveSupport::Dependencies.autoload_paths.collect{|p| Pathname.new(p)} + ActiveSupport::Dependencies.autoload_paths = pathnames + ActiveSupport::Dependencies.autoload_once_paths = pathnames + + assert ! ActiveSupport::Dependencies.autoloaded?("ModuleFolder") + assert ! ActiveSupport::Dependencies.autoloaded?("ModuleFolder::NestedClass") + assert ! ActiveSupport::Dependencies.autoloaded?(ModuleFolder) + + 1 if ModuleFolder::NestedClass # 1 if to avoid warning + assert ! ActiveSupport::Dependencies.autoloaded?(ModuleFolder::NestedClass) + end + ensure + Object.class_eval { remove_const :ModuleFolder } + ActiveSupport::Dependencies.autoload_once_paths = [] + end + def test_application_should_special_case_application_controller with_autoloading_fixtures do require_dependency 'application' |