summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-08-09 03:35:48 +0200
committererdgeist <erdgeist@erdgeist.org>2026-08-09 03:35:48 +0200
commitd16161eab9029a509951146b80334c304c35fd34 (patch)
tree87dd7426389b0e27b31925dc28c76a442eb721b8 /test
parent20c735b0c5a2db9b8984848253ad99332d6211a8 (diff)
Refuse destroying an asset that is still attached
Diffstat (limited to 'test')
-rw-r--r--test/models/asset_destroy_test.rb49
1 files changed, 17 insertions, 32 deletions
diff --git a/test/models/asset_destroy_test.rb b/test/models/asset_destroy_test.rb
index 2f38d692..54512b16 100644
--- a/test/models/asset_destroy_test.rb
+++ b/test/models/asset_destroy_test.rb
@@ -8,29 +8,6 @@ class AssetDestroyTest < ActiveSupport::TestCase
8 :upload_content_type => "image/png") 8 :upload_content_type => "image/png")
9 end 9 end
10 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 11 test "an unattached asset is still witnessed" do
35 @asset.destroy_witnessed!(:user => @user) 12 @asset.destroy_witnessed!(:user => @user)
36 13
@@ -49,16 +26,24 @@ class AssetDestroyTest < ActiveSupport::TestCase
49 assert_nil action.action_participants.first.subject 26 assert_nil action.action_participants.first.subject
50 end 27 end
51 28
52 test "destroying an asset attached to a restricted node needs the redaktion role" do 29 test "destruction is refused while the asset is attached" do
53 editor = User.create!(:login => "asset_gate", :email => "ag@example.com", 30 node = Node.root.children.create!(:slug => "asset_destroy_attached")
54 :password => "secret", :password_confirmation => "secret") 31 node.attach_asset!(@asset, :user => @user)
55 updates = Node.root.children.create!(:slug => "updates") 32
56 node = updates.children.create!(:slug => "gated-attachment") 33 assert_raises(ActiveRecord::RecordInvalid) { @asset.destroy_witnessed!(:user => @user) }
57 node.reload.attach_asset!(@asset, :user => nil) 34 assert Asset.exists?(@asset.id)
35 assert_equal 0, NodeAction.where(:action => "asset_destroy").count
36 end
37
38 test "an attachment on a draft alone is enough to refuse" do
39 node = Node.root.children.create!(:slug => "asset_destroy_draft_only")
40 node.attach_asset!(@asset, :user => @user)
41 node.publish_draft!(@user)
42 node.lock_for_editing!(@user)
43 node.create_new_draft(@user)
44 node.head.related_assets.destroy_all
58 45
59 error = assert_raises(ActiveRecord::RecordInvalid) { @asset.destroy_witnessed!(:user => editor) } 46 assert_raises(ActiveRecord::RecordInvalid) { @asset.destroy_witnessed!(:user => @user) }
60 assert_includes error.message,
61 I18n.t("activerecord.errors.models.asset.attributes.base.not_permitted")
62 assert Asset.exists?(@asset.id) 47 assert Asset.exists?(@asset.id)
63 end 48 end
64end 49end