From a5dda97602f2188a13cbcab5c7e9a5ba84ba876b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 5 Jul 2010 12:50:08 +0200 Subject: Define a convention for descendants and subclasses. The former should be symmetric with ancestors and include all children. However, it should not include self since ancestors + descendants should not have duplicated. The latter is symmetric to superclass in the sense it only includes direct children. By adopting a convention, we expect to have less conflict with other frameworks, as Datamapper. For this moment, to ensure ActiveModel::Validations can be used with Datamapper, we should always call ActiveSupport::DescendantsTracker.descendants(self) internally instead of self.descendants avoiding conflicts. --- .../test/core_ext/object_and_class_ext_test.rb | 49 ---------------------- 1 file changed, 49 deletions(-) (limited to 'activesupport/test/core_ext/object_and_class_ext_test.rb') 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 5e03389dc2..6588f2e345 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -40,55 +40,6 @@ 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 < ActiveSupport::TestCase class DuckTime def acts_like_time? -- cgit v1.2.3