diff options
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/extending.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/object_and_class_ext_test.rb | 9 |
3 files changed, 13 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 6d3fd44368..e6e8f2d1ea 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fix Object.subclasses_of to only return currently defined objects [Jonathan Viney <jonathan@bluewire.net.nz>] + * Fix constantize to properly handle names beginning with '::'. [Nicholas Seckar] * Make String#last return the string instead of nil when it is shorter than the limit [Scott Barron]. diff --git a/activesupport/lib/active_support/core_ext/object/extending.rb b/activesupport/lib/active_support/core_ext/object/extending.rb index 8c638f83c2..9abdfc0bc9 100644 --- a/activesupport/lib/active_support/core_ext/object/extending.rb +++ b/activesupport/lib/active_support/core_ext/object/extending.rb @@ -8,7 +8,7 @@ class Object #:nodoc: def subclasses_of(*superclasses) subclasses = [] ObjectSpace.each_object(Class) do |k| - next if (k.ancestors & superclasses).empty? || superclasses.include?(k) || k.to_s.include?("::") || subclasses.include?(k) + next if (k.ancestors & superclasses).empty? || superclasses.include?(k) || k.to_s.include?("::") || subclasses.include?(k) || !Object.const_defined?(k.to_s.to_sym) subclasses << k end subclasses @@ -42,4 +42,4 @@ class Object #:nodoc: block.bind(self)[*arguments] end end -end
\ No newline at end of file +end diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index 5d7a06d08d..6a100e813b 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -7,6 +7,9 @@ class ClassB < ClassA; end class ClassC < ClassB; end class ClassD < ClassA; end +class ClassI; end +class ClassJ < ClassI; end + module Bar def bar; end end @@ -31,6 +34,12 @@ class ClassExtTest < Test::Unit::TestCase assert !defined?(ClassC) assert !defined?(ClassD) end + + def test_subclasses_of + assert_equal [ClassJ], Object.subclasses_of(ClassI) + ClassI.remove_subclasses + assert_equal [], Object.subclasses_of(ClassI) + end end class ObjectTests < Test::Unit::TestCase |