summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-17 22:11:44 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-17 22:11:44 +0200
commit71a95f4ca6460a7c2bc345e8b32dbef03d6dd985 (patch)
tree48ba0ccdc1941343bdb2632ec5724ce38fd9ecfb /test
parente3021c88a0ce35b4c069e148a5d82bb1acbd3c91 (diff)
Refuse destroying nodes that still have children
NestedTree's before_destroy silently delete_all'd the whole subtree, bypassing every per-node cleanup. Nodes are never destroyed recursively; descendants must be removed individually.
Diffstat (limited to 'test')
-rw-r--r--test/models/node_test.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/models/node_test.rb b/test/models/node_test.rb
index 4401651..9c4834e 100644
--- a/test/models/node_test.rb
+++ b/test/models/node_test.rb
@@ -770,4 +770,41 @@ class NodeTest < ActiveSupport::TestCase
770 node.default_template_name = "standard_template" 770 node.default_template_name = "standard_template"
771 assert node.valid? 771 assert node.valid?
772 end 772 end
773
774 test "destroying a node with children is refused" do
775 parent = Node.root.children.create!(:slug => "destroy_guard_parent")
776 parent.children.create!(:slug => "destroy_guard_child")
777
778 assert_no_difference "Node.count" do
779 assert_not parent.destroy
780 end
781 assert parent.errors[:base].any?
782 end
783
784 test "destroying a childless node leaves no orphaned pages or asset links" do
785 node = create_node_with_published_page
786 page_ids = node.pages.pluck(:id)
787 asset = Asset.create!(:name => "destroy cascade probe",
788 :upload_file_name => "test_image.png",
789 :upload_content_type => "image/png",
790 :upload_file_size => 49854,
791 :upload_updated_at => Time.current)
792 node.head.related_assets.create!(:asset_id => asset.id, :position => 1)
793
794 node.destroy
795
796 assert_equal 0, Page.where(:id => page_ids).count
797 assert_equal 0, RelatedAsset.where(:page_id => page_ids).count
798 end
799
800 test "destroying a node also removes its autosave page" do
801 node = create_node_with_published_page
802 node.lock_for_editing!(@user1)
803 node.autosave!({:title => "in flight"}, @user1)
804 autosave_id = node.autosave_id
805
806 node.destroy
807
808 assert_equal 0, Page.where(:id => autosave_id).count
809 end
773end 810end