summaryrefslogtreecommitdiff
path: root/test/models/asset_destroy_test.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-23 04:12:39 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-23 04:12:39 +0200
commit6ef98ad444631b1d5ba67bb16aaaa2afdfa53ae0 (patch)
tree44c23d4efccfdbe0496a3d09fbdb1b33212999de /test/models/asset_destroy_test.rb
parent49a80c2f48531edc2a2719d77d3c5a8c111289dd (diff)
Witness asset destruction, naming every node it strips
Diffstat (limited to 'test/models/asset_destroy_test.rb')
-rw-r--r--test/models/asset_destroy_test.rb51
1 files changed, 51 insertions, 0 deletions
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 @@
1require "test_helper"
2
3class AssetDestroyTest < ActiveSupport::TestCase
4 def setup
5 @user = users(:quentin)
6 @asset = Asset.create!(:name => "Doomed asset",
7 :upload_file_name => "doomed.png",
8 :upload_content_type => "image/png")
9 end
10
11 test "destroying an attached asset logs nodes and asset as participants" do
12 node = Node.root.children.create!(:slug => "asset_destroy_attached")
13 node.attach_asset!(@asset, :user => @user)
14
15 @asset.destroy_witnessed!(:user => @user)
16
17 action = NodeAction.where(:action => "asset_destroy").last
18 subjects = action.action_participants.map { |p| [p.subject_type, p.subject_id] }
19 assert_includes subjects, ["Asset", @asset.id]
20 assert_includes subjects, ["Node", node.id]
21 assert_equal [node.unique_name], action.metadata["detached_from"]
22 end
23
24 test "records which nodes lost their headline" do
25 node = Node.root.children.create!(:slug => "asset_destroy_headline")
26 node.attach_asset!(@asset, :user => @user, :headline => true)
27
28 @asset.destroy_witnessed!(:user => @user)
29
30 action = NodeAction.where(:action => "asset_destroy").last
31 assert_equal [node.unique_name], action.metadata["headline_removed_from"]
32 end
33
34 test "an unattached asset is still witnessed" do
35 @asset.destroy_witnessed!(:user => @user)
36
37 action = NodeAction.where(:action => "asset_destroy").last
38 assert_equal [["Asset", @asset.id]],
39 action.action_participants.map { |p| [p.subject_type, p.subject_id] }
40 assert_nil action.node_id
41 end
42
43 test "the entry outlives the asset" do
44 @asset.destroy_witnessed!(:user => @user)
45 action = NodeAction.where(:action => "asset_destroy").last
46
47 assert_not Asset.exists?(@asset.id)
48 assert_equal "Doomed asset", action.metadata["asset_name"]
49 assert_nil action.action_participants.first.subject
50 end
51end