mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixed an issue where reloading of removed dependencies would cause an unexpected circular dependency error
This commit is contained in:
parent
3c2fe5ccc5
commit
4fa8c8b52f
2 changed files with 20 additions and 0 deletions
|
@ -665,6 +665,14 @@ module ActiveSupport #:nodoc:
|
||||||
constants = normalized.split('::')
|
constants = normalized.split('::')
|
||||||
to_remove = constants.pop
|
to_remove = constants.pop
|
||||||
|
|
||||||
|
# Remove the file path from the loaded list.
|
||||||
|
file_path = search_for_file(const.underscore)
|
||||||
|
if file_path
|
||||||
|
expanded = File.expand_path(file_path)
|
||||||
|
expanded.sub!(/\.rb\z/, '')
|
||||||
|
self.loaded.delete(expanded)
|
||||||
|
end
|
||||||
|
|
||||||
if constants.empty?
|
if constants.empty?
|
||||||
parent = Object
|
parent = Object
|
||||||
else
|
else
|
||||||
|
|
|
@ -948,6 +948,18 @@ class DependenciesTest < ActiveSupport::TestCase
|
||||||
Object.class_eval { remove_const :A if const_defined?(:A) }
|
Object.class_eval { remove_const :A if const_defined?(:A) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_access_unloaded_constants_for_reload
|
||||||
|
with_autoloading_fixtures do
|
||||||
|
assert_kind_of Module, A
|
||||||
|
assert_kind_of Class, A::B # Necessary to load A::B for the test
|
||||||
|
ActiveSupport::Dependencies.mark_for_unload(A::B)
|
||||||
|
ActiveSupport::Dependencies.remove_unloadable_constants!
|
||||||
|
|
||||||
|
A::B # Make sure no circular dependency error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_autoload_once_paths_should_behave_when_recursively_loading
|
def test_autoload_once_paths_should_behave_when_recursively_loading
|
||||||
with_loading 'dependencies', 'autoloading_fixtures' do
|
with_loading 'dependencies', 'autoloading_fixtures' do
|
||||||
ActiveSupport::Dependencies.autoload_once_paths = [ActiveSupport::Dependencies.autoload_paths.last]
|
ActiveSupport::Dependencies.autoload_once_paths = [ActiveSupport::Dependencies.autoload_paths.last]
|
||||||
|
|
Loading…
Reference in a new issue