Permalink
Browse files

Fix Reloadable to handle the case where a class that has been 'remove…

…d' has not yet been garbage collected.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3528 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 62aa060 commit 1aaeb2113b64c9e5a26d7e4a24e868899b89f614 @seckar seckar committed Feb 4, 2006
View
@@ -1,5 +1,7 @@
*SVN*
+* Fix Reloadable to handle the case where a class that has been 'removed' has not yet been garbage collected. [Nicholas Seckar]
+
* Don't allow Reloadable to be included into Modules.
* Remove LoadingModule. [Nicholas Seckar]
@@ -9,8 +9,15 @@ def subclasses
def remove_class(*klasses)
klasses.each do |klass|
+ # Skip this class if there is nothing bound to this name
+ next unless defined?(klass.name)
+
basename = klass.to_s.split("::").last
parent = klass.parent
+
+ # Skip this class if it does not match the current one bound to this name
+ next unless klass = parent.const_get(basename)
+
parent.send :remove_const, basename unless parent == klass
end
end
@@ -5,9 +5,6 @@
module ReloadableTestSandbox
- module AModuleIncludingReloadable
- include Reloadable
- end
class AReloadableClass
include Reloadable
end
@@ -43,9 +40,6 @@ class ASubclassofAOnlySubclassReloadableClassWhichWasSubclassingAReloadableClass
end
class ReloadableTest < Test::Unit::TestCase
- def test_modules_do_not_receive_reloadable_method
- assert ! ReloadableTestSandbox::AModuleIncludingReloadable.respond_to?(:reloadable?)
- end
def test_classes_receive_reloadable
assert ReloadableTestSandbox::AReloadableClass.respond_to?(:reloadable?)
end
@@ -76,7 +70,6 @@ def test_removable_classes
)
non_reloadables = %w(
ANonReloadableSubclass
- AModuleIncludingReloadable
OnlySubclassesReloadable
)

0 comments on commit 1aaeb21

Please sign in to comment.