Skip to content
Browse files

Merge pull request #2675 from jdelStrother/load_once_pathnames_fix

Fix autoload_once_paths when using Pathnames & ruby 1.9
  • Loading branch information...
2 parents 289540e + e0714ee commit 2f88743c30ef3dcc7616a6cf18331b84372172b8 @josevalim josevalim committed Aug 24, 2011
Showing with 20 additions and 1 deletion.
  1. +2 −1 activesupport/lib/active_support/dependencies.rb
  2. +18 −0 activesupport/test/dependencies_test.rb
View
3 activesupport/lib/active_support/dependencies.rb
@@ -421,7 +421,8 @@ def autoloadable_module?(path_suffix)
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
View
18 activesupport/test/dependencies_test.rb
@@ -520,6 +520,24 @@ def test_autoload_once_paths_do_not_add_to_autoloaded_constants
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'

0 comments on commit 2f88743

Please sign in to comment.
Something went wrong with that request. Please try again.