Skip to content
Browse files

Apply [5781] and [5782] to RC

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5783 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent debd9ea commit da8a896d86e792f0f59bec8381cb162375b4c2b5 @seckar seckar committed Dec 24, 2006
View
2 activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*1.4.0 RC2*
+* Update load once paths to prevent nested once constants from being detected and claimed by an external non-once load. [Nicholas Seckar]
+
* Deprecation: silence warnings when reporting test errors. [Jeremy Kemper]
* Fix remove_constant to correctly handle constant names of the form "::A::...". References #6720. [Nicholas Seckar]
View
8 activesupport/lib/active_support/dependencies.rb
@@ -130,7 +130,7 @@ def qualified_const_defined?(path)
# Given +path+, a filesystem path to a ruby file, return an array of constant
# paths which would cause Dependencies to attempt to load this file.
#
- def loadable_constants_for_path(path, bases = load_paths - load_once_paths)
+ def loadable_constants_for_path(path, bases = load_paths)
path = $1 if path =~ /\A(.*)\.rb\Z/
expanded_path = File.expand_path(path)
@@ -169,6 +169,10 @@ def autoloadable_module?(path_suffix)
nil
end
+ def load_once_path?(path)
+ load_once_paths.any? { |base| path.starts_with? base }
+ end
+
# Attempt to autoload the provided module name by searching for a directory
# matching the expect path suffix. If found, the module is created and assigned
# to +into+'s constants with the name +const_name+. Provided that the directory
@@ -200,7 +204,7 @@ def load_file(path, const_paths = loadable_constants_for_path(path))
result = load_without_new_constant_marking path
end
- autoloaded_constants.concat newly_defined_paths
+ autoloaded_constants.concat newly_defined_paths unless load_once_path?(path)
autoloaded_constants.uniq!
log "loading #{path} defined #{newly_defined_paths * ', '}" unless newly_defined_paths.empty?
return result
View
28 activesupport/test/dependencies_test.rb
@@ -702,4 +702,32 @@ def test_remove_constant_handles_double_colon_at_start
assert ! defined?(DeleteMe)
end
+ def test_load_once_constants_should_not_be_unloaded
+ with_loading 'autoloading_fixtures' do
+ Dependencies.load_once_paths = Dependencies.load_paths
+ ::A
+ assert defined?(A)
+ Dependencies.clear
+ assert defined?(A)
+ end
+ ensure
+ Dependencies.load_once_paths = []
+ Object.send :remove_const, :A rescue nil
+ end
+
+ def test_load_once_paths_should_behave_when_recursively_loading
+ with_loading 'dependencies', 'autoloading_fixtures' do
+ Dependencies.load_once_paths = [Dependencies.load_paths.last]
+ CrossSiteDepender.nil?
+ assert defined?(CrossSiteDependency)
+ assert ! Dependencies.autoloaded?(CrossSiteDependency),
+ "CrossSiteDependency shouldn't be marked as autoloaded!"
+ Dependencies.clear
+ assert defined?(CrossSiteDependency),
+ "CrossSiteDependency shouldn't have been unloaded!"
+ end
+ ensure
+ Dependencies.load_once_paths = []
+ end
+
end

0 comments on commit da8a896

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