aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/object_and_class_ext_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2010-02-09 18:03:14 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2010-02-09 18:20:57 -0800
commitd1938953f416ac945b591251567d51e30ee2a6a4 (patch)
tree9f0b99f6d01a6e955a1a2a7a42ef4b68cee52478 /activesupport/test/core_ext/object_and_class_ext_test.rb
parentfa2ff95d4b783751f42378447331385c469e4775 (diff)
downloadrails-d1938953f416ac945b591251567d51e30ee2a6a4.tar.gz
rails-d1938953f416ac945b591251567d51e30ee2a6a4.tar.bz2
rails-d1938953f416ac945b591251567d51e30ee2a6a4.zip
Reinstate Object.subclasses_of and Class#descendents for plugin compat.
This reverts commits 7d312e54bad9c39634c137caec07dfc8df471650, 5f981ff0294ba45aa44ad15aa063970b29aeec44, f85f5dfc8ffefff174b695c6363211d342f77a57, 245bfafe335ff883f7a096eab95ac22fe2848679, and ec7c642f5fe60afc857aa64f1a9b4c2be56f9d70
Diffstat (limited to 'activesupport/test/core_ext/object_and_class_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/object_and_class_ext_test.rb50
1 files changed, 50 insertions, 0 deletions
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 0b2a9c418e..f31e7774e9 100644
--- a/activesupport/test/core_ext/object_and_class_ext_test.rb
+++ b/activesupport/test/core_ext/object_and_class_ext_test.rb
@@ -1,6 +1,7 @@
require 'abstract_unit'
require 'active_support/time'
require 'active_support/core_ext/object'
+require 'active_support/core_ext/class/subclasses'
class ClassA; end
class ClassB < ClassA; end
@@ -39,6 +40,55 @@ class Foo
include Bar
end
+class ClassExtTest < Test::Unit::TestCase
+ def test_subclasses_of_should_find_nested_classes
+ assert Class.subclasses_of(ClassK).include?(Nested::ClassL)
+ end
+
+ def test_subclasses_of_should_not_return_removed_classes
+ # First create the removed class
+ old_class = Nested.class_eval { remove_const :ClassL }
+ new_class = Class.new(ClassK)
+ Nested.const_set :ClassL, new_class
+ assert_equal "Nested::ClassL", new_class.name # Sanity check
+
+ subclasses = Class.subclasses_of(ClassK)
+ assert subclasses.include?(new_class)
+ assert ! subclasses.include?(old_class)
+ ensure
+ Nested.const_set :ClassL, old_class unless defined?(Nested::ClassL)
+ end
+
+ def test_subclasses_of_should_not_trigger_const_missing
+ const_missing = false
+ Nested.on_const_missing { const_missing = true }
+
+ subclasses = Class.subclasses_of ClassK
+ assert !const_missing
+ assert_equal [ Nested::ClassL ], subclasses
+
+ removed = Nested.class_eval { remove_const :ClassL } # keep it in memory
+ subclasses = Class.subclasses_of ClassK
+ assert !const_missing
+ assert subclasses.empty?
+ ensure
+ Nested.const_set :ClassL, removed unless defined?(Nested::ClassL)
+ end
+
+ def test_subclasses_of_with_multiple_roots
+ classes = Class.subclasses_of(ClassI, ClassK)
+ assert_equal %w(ClassJ Nested::ClassL), classes.collect(&:to_s).sort
+ end
+
+ def test_subclasses_of_doesnt_find_anonymous_classes
+ assert_equal [], Class.subclasses_of(Foo)
+ bar = Class.new(Foo)
+ assert_nothing_raised do
+ assert_equal [bar], Class.subclasses_of(Foo)
+ end
+ end
+end
+
class ObjectTests < Test::Unit::TestCase
class DuckTime
def acts_like_time?