diff options
author | Rolf Timmermans <r.timmermans@voormedia.com> | 2011-03-13 16:52:34 +0100 |
---|---|---|
committer | Rolf Timmermans <r.timmermans@voormedia.com> | 2011-03-13 17:04:01 +0100 |
commit | 76e4e2fa468593c42623472055d329dfeb577c49 (patch) | |
tree | dd6c654db48363a192a496a419e9cfa62f2d6d93 /activesupport/test/descendants_tracker_test.rb | |
parent | 56a0cba7bedea46bb01f7f9e8db9398aeeac950b (diff) | |
download | rails-76e4e2fa468593c42623472055d329dfeb577c49.tar.gz rails-76e4e2fa468593c42623472055d329dfeb577c49.tar.bz2 rails-76e4e2fa468593c42623472055d329dfeb577c49.zip |
Refactored AS::DescendantsTracker test cases so they can be tested without AS::Dependencies.
Diffstat (limited to 'activesupport/test/descendants_tracker_test.rb')
-rw-r--r-- | activesupport/test/descendants_tracker_test.rb | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/activesupport/test/descendants_tracker_test.rb b/activesupport/test/descendants_tracker_test.rb deleted file mode 100644 index 79fb893592..0000000000 --- a/activesupport/test/descendants_tracker_test.rb +++ /dev/null @@ -1,77 +0,0 @@ -require 'abstract_unit' -require 'test/unit' -require 'active_support' -require 'active_support/core_ext/hash/slice' - -class DescendantsTrackerTest < Test::Unit::TestCase - class Parent - extend ActiveSupport::DescendantsTracker - end - - class Child1 < Parent - end - - class Child2 < Parent - end - - class Grandchild1 < Child1 - end - - class Grandchild2 < Child1 - end - - ALL = [Parent, Child1, Child2, Grandchild1, Grandchild2] - - def test_descendants - assert_equal [Child1, Grandchild1, Grandchild2, Child2], Parent.descendants - assert_equal [Grandchild1, Grandchild2], Child1.descendants - assert_equal [], Child2.descendants - end - - def test_direct_descendants - assert_equal [Child1, Child2], Parent.direct_descendants - assert_equal [Grandchild1, Grandchild2], Child1.direct_descendants - assert_equal [], Child2.direct_descendants - end - - def test_clear_with_autoloaded_parent_children_and_granchildren - mark_as_autoloaded(*ALL) do - ActiveSupport::DescendantsTracker.clear - ALL.each do |k| - assert ActiveSupport::DescendantsTracker.descendants(k).empty? - end - end - end - - def test_clear_with_autoloaded_children_and_granchildren - mark_as_autoloaded Child1, Grandchild1, Grandchild2 do - ActiveSupport::DescendantsTracker.clear - assert_equal [Child2], Parent.descendants - assert_equal [], Child2.descendants - end - end - - def test_clear_with_autoloaded_granchildren - mark_as_autoloaded Grandchild1, Grandchild2 do - ActiveSupport::DescendantsTracker.clear - assert_equal [Child1, Child2], Parent.descendants - assert_equal [], Child1.descendants - assert_equal [], Child2.descendants - end - end - - protected - - def mark_as_autoloaded(*klasses) - old_autoloaded = ActiveSupport::Dependencies.autoloaded_constants.dup - ActiveSupport::Dependencies.autoloaded_constants = klasses.map(&:name) - - old_descendants = ActiveSupport::DescendantsTracker.class_eval("@@direct_descendants").dup - old_descendants.each { |k, v| old_descendants[k] = v.dup } - - yield - ensure - ActiveSupport::Dependencies.autoloaded_constants = old_autoloaded - ActiveSupport::DescendantsTracker.class_eval("@@direct_descendants").replace(old_descendants) - end -end
\ No newline at end of file |