2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2018-09-29 20:50:43 -04:00
|
|
|
require_relative "abstract_unit"
|
2016-08-06 12:03:25 -04:00
|
|
|
require "active_support/descendants_tracker"
|
|
|
|
require "active_support/dependencies"
|
2018-09-29 20:50:43 -04:00
|
|
|
require_relative "descendants_tracker_test_cases"
|
2011-03-13 11:52:34 -04:00
|
|
|
|
2012-01-05 20:12:46 -05:00
|
|
|
class DescendantsTrackerWithAutoloadingTest < ActiveSupport::TestCase
|
2011-03-13 11:52:34 -04:00
|
|
|
include DescendantsTrackerTestCases
|
|
|
|
|
2013-03-30 04:31:42 -04:00
|
|
|
def test_clear_with_autoloaded_parent_children_and_grandchildren
|
2011-03-13 11:52:34 -04:00
|
|
|
mark_as_autoloaded(*ALL) do
|
|
|
|
ActiveSupport::DescendantsTracker.clear
|
|
|
|
ALL.each do |k|
|
2018-01-25 18:16:57 -05:00
|
|
|
assert_empty ActiveSupport::DescendantsTracker.descendants(k)
|
2011-03-13 11:52:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-30 04:31:42 -04:00
|
|
|
def test_clear_with_autoloaded_children_and_grandchildren
|
2011-03-13 11:52:34 -04:00
|
|
|
mark_as_autoloaded Child1, Grandchild1, Grandchild2 do
|
|
|
|
ActiveSupport::DescendantsTracker.clear
|
2012-06-30 15:51:57 -04:00
|
|
|
assert_equal_sets [Child2], Parent.descendants
|
|
|
|
assert_equal_sets [], Child2.descendants
|
2011-03-13 11:52:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-30 04:31:42 -04:00
|
|
|
def test_clear_with_autoloaded_grandchildren
|
2011-03-13 11:52:34 -04:00
|
|
|
mark_as_autoloaded Grandchild1, Grandchild2 do
|
|
|
|
ActiveSupport::DescendantsTracker.clear
|
2012-06-30 15:51:57 -04:00
|
|
|
assert_equal_sets [Child1, Child2], Parent.descendants
|
|
|
|
assert_equal_sets [], Child1.descendants
|
|
|
|
assert_equal_sets [], Child2.descendants
|
2011-03-13 11:52:34 -04:00
|
|
|
end
|
|
|
|
end
|
2012-01-06 17:42:53 -05:00
|
|
|
end
|