From 6ef98ad444631b1d5ba67bb16aaaa2afdfa53ae0 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Thu, 23 Jul 2026 04:12:39 +0200 Subject: Witness asset destruction, naming every node it strips --- test/models/asset_destroy_test.rb | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/models/asset_destroy_test.rb (limited to 'test/models') diff --git a/test/models/asset_destroy_test.rb b/test/models/asset_destroy_test.rb new file mode 100644 index 00000000..5583f685 --- /dev/null +++ b/test/models/asset_destroy_test.rb @@ -0,0 +1,51 @@ +require "test_helper" + +class AssetDestroyTest < ActiveSupport::TestCase + def setup + @user = users(:quentin) + @asset = Asset.create!(:name => "Doomed asset", + :upload_file_name => "doomed.png", + :upload_content_type => "image/png") + end + + test "destroying an attached asset logs nodes and asset as participants" do + node = Node.root.children.create!(:slug => "asset_destroy_attached") + node.attach_asset!(@asset, :user => @user) + + @asset.destroy_witnessed!(:user => @user) + + action = NodeAction.where(:action => "asset_destroy").last + subjects = action.action_participants.map { |p| [p.subject_type, p.subject_id] } + assert_includes subjects, ["Asset", @asset.id] + assert_includes subjects, ["Node", node.id] + assert_equal [node.unique_name], action.metadata["detached_from"] + end + + test "records which nodes lost their headline" do + node = Node.root.children.create!(:slug => "asset_destroy_headline") + node.attach_asset!(@asset, :user => @user, :headline => true) + + @asset.destroy_witnessed!(:user => @user) + + action = NodeAction.where(:action => "asset_destroy").last + assert_equal [node.unique_name], action.metadata["headline_removed_from"] + end + + test "an unattached asset is still witnessed" do + @asset.destroy_witnessed!(:user => @user) + + action = NodeAction.where(:action => "asset_destroy").last + assert_equal [["Asset", @asset.id]], + action.action_participants.map { |p| [p.subject_type, p.subject_id] } + assert_nil action.node_id + end + + test "the entry outlives the asset" do + @asset.destroy_witnessed!(:user => @user) + action = NodeAction.where(:action => "asset_destroy").last + + assert_not Asset.exists?(@asset.id) + assert_equal "Doomed asset", action.metadata["asset_name"] + assert_nil action.action_participants.first.subject + end +end -- cgit v1.3