summaryrefslogtreecommitdiff
path: root/test
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
parent49a80c2f48531edc2a2719d77d3c5a8c111289dd (diff)
Witness asset destruction, naming every node it strips
Diffstat (limited to 'test')
-rw-r--r--test/controllers/assets_controller_test.rb10
-rw-r--r--test/models/asset_destroy_test.rb51
2 files changed, 61 insertions, 0 deletions
diff --git a/test/controllers/assets_controller_test.rb b/test/controllers/assets_controller_test.rb
index 05fc6ded..0e251aad 100644
--- a/test/controllers/assets_controller_test.rb
+++ b/test/controllers/assets_controller_test.rb
@@ -182,6 +182,16 @@ class AssetsControllerTest < ActionController::TestCase
182 assert !Dir.exist?(upload_dir), "Upload directory should be removed after destroy" 182 assert !Dir.exist?(upload_dir), "Upload directory should be removed after destroy"
183 end 183 end
184 184
185 test "destroy is witnessed in the action log with the current user" do
186 asset = Asset.create!(:name => 'Witness me',
187 :upload_file_name => 'w.png',
188 :upload_content_type => 'image/png')
189 assert_difference 'NodeAction.where(:action => "asset_destroy").count' do
190 delete :destroy, params: { id: asset.id }
191 end
192 assert_equal users(:quentin), NodeAction.last.user
193 end
194
185 # --- URL helpers --- 195 # --- URL helpers ---
186 196
187 test "upload url returns correct path for original" do 197 test "upload url returns correct path for original" do
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