Skip to content

Commit

Permalink
test orphan_strategy: :destroy deletes leafs first
Browse files Browse the repository at this point in the history
validates #635
  • Loading branch information
kbrock committed Jul 17, 2023
1 parent 5c63748 commit f1b8d95
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/concerns/orphan_strategies_test.rb
Expand Up @@ -24,6 +24,18 @@ def test_orphan_rootify_strategy

def test_orphan_destroy_strategy
AncestryTestDatabase.with_model orphan_strategy: :destroy, :depth => 3, :width => 3 do |model, roots|
model.class_eval do
# verify we are destroying leafs to child
# some implementations leverage the parent
before_destroy :verify_parent_exists

def verify_parent_exists
if has_parent? && !self.class.where(:id => parent_id).exists?
raise "issues with #{id} (ancestry #{ancestry || "root"})"
end
end
end

root = roots.first.first
assert_difference 'model.count', -root.subtree.size do
root.destroy
Expand Down Expand Up @@ -68,6 +80,7 @@ def test_orphan_adopt_strategy
end
end

# DEPRECATED - please see test_apply_orphan_strategy_none for pattern instead
def test_override_apply_orphan_strategy
AncestryTestDatabase.with_model orphan_strategy: :destroy do |model, roots|
root = model.create!
Expand Down

0 comments on commit f1b8d95

Please sign in to comment.