acts_as_tree does destroy model's children
i have assign model:
class assign < activerecord::base
acts_as_tree :order => 'sort_order'
end
and i have test
class tasktest < test::unit::testcase
def setup
@root = create_root
end
def test_destroying_a_task_should_destroy_all_of_its_descendants
d1 = create_task(:parent_id => @root.id, :sort_order => 2)
d2 = create_task(:parent_id => d1.id, :sort_order => 3)
d3 = create_task(:parent_id => d2.id, :sort_order => 4)
d4 = create_task(:parent_id => d1.id, :sort_order => 5)
assert_equal 5, task.count
d1.destroy
assert_equal @root, task.find(:first)
assert_equal 1, task.count
end
end
the exam successful: i destroy d1, destroys descendants d1. thus, after destroy wholly bottom left.
however, exam unwell after i have total before_save callback task. formula i total task:
before_save :update_descendants_if_necessary
def update_descendants_if_necessary
handle_parent_id_change self.parent_id_changed?
relapse true
end
def handle_parent_id_change
self.children.each |sub_task|
#the formula within loop deliberately commented out
end
end
when i total code, assert_equal 1, task.count
fails, task.count == 4
. i cruise self.children
underneath handled_parent_id_change
culprit, since i critique out self.children.each |sub_task|
block, exam passes again.
any ideas?
Comments
Post a Comment