summaryrefslogtreecommitdiff
path: root/test/controllers/assets_controller_test.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-08-09 03:33:55 +0200
committererdgeist <erdgeist@erdgeist.org>2026-08-09 03:33:55 +0200
commit20c735b0c5a2db9b8984848253ad99332d6211a8 (patch)
treea4ae71c53c403c1a7740db624e43fd3163e37ab7 /test/controllers/assets_controller_test.rb
parent5203b80f47786b8adc169e80d89cd69159c44b62 (diff)
Attach assets to the draft instead of to every lifecycle row
Node#attach_asset! writes to the node's draft alone, creating one from the head when none is pending. It refuses when another user holds the lock, and when an autosave already exists The asset_attach verb goes with it. create_new_draft names the editor on the draft it creates and the publish entry's asset delta reports the attachment.
Diffstat (limited to 'test/controllers/assets_controller_test.rb')
-rw-r--r--test/controllers/assets_controller_test.rb34
1 files changed, 25 insertions, 9 deletions
diff --git a/test/controllers/assets_controller_test.rb b/test/controllers/assets_controller_test.rb
index 467e1a68..aa3e00e6 100644
--- a/test/controllers/assets_controller_test.rb
+++ b/test/controllers/assets_controller_test.rb
@@ -94,7 +94,7 @@ class AssetsControllerTest < ActionController::TestCase
94 94
95 # --- create with attach --- 95 # --- create with attach ---
96 96
97 test "create with node_id attaches the asset to the node's draft" do 97 test "create with node_id attaches the asset to an existing draft" do
98 node = Node.root.children.create!(:slug => "asset_attach_target") 98 node = Node.root.children.create!(:slug => "asset_attach_target")
99 99
100 post :create, params: { asset: { name: 'Attach me' }, node_id: node.id } 100 post :create, params: { asset: { name: 'Attach me' }, node_id: node.id }
@@ -102,7 +102,21 @@ class AssetsControllerTest < ActionController::TestCase
102 assert_response :redirect 102 assert_response :redirect
103 asset = Asset.last 103 asset = Asset.last
104 assert_includes node.draft.assets.reload, asset 104 assert_includes node.draft.assets.reload, asset
105 assert_equal I18n.t("flash.assets.attached", :title => node.title), flash[:notice] 105 assert_equal I18n.t("flash.assets.attached_to_draft", :title => node.title), flash[:notice]
106 end
107
108 test "create with node_id creates a draft when none is pending" do
109 node = Node.root.children.create!(:slug => "asset_attach_no_draft")
110 node.publish_draft!(users(:quentin))
111 assert_nil node.reload.draft
112
113 post :create, params: { asset: { name: 'Attach me too' }, node_id: node.id }
114
115 node.reload
116 assert_includes node.draft.assets.reload, Asset.last
117 assert_empty node.head.assets.reload
118 assert_equal users(:quentin), node.draft.editor
119 assert_equal I18n.t("flash.assets.attached_new_draft", :title => node.title), flash[:notice]
106 end 120 end
107 121
108 test "create against a foreign-locked node keeps the asset but refuses the attach" do 122 test "create against a foreign-locked node keeps the asset but refuses the attach" do
@@ -133,14 +147,16 @@ class AssetsControllerTest < ActionController::TestCase
133 assert_equal node_path(node), flash[:headline_kept_path] 147 assert_equal node_path(node), flash[:headline_kept_path]
134 end 148 end
135 149
136 test "create with node_id writes an asset_create and an asset_attach entry" do 150 test "create with node_id writes only an asset_create entry" do
137 node = Node.root.children.create!(:slug => "asset_log_pair") 151 node = Node.root.children.create!(:slug => "asset_log_single")
138 assert_difference 'NodeAction.where(:action => "asset_create").count' do 152
139 assert_difference 'NodeAction.where(:action => "asset_attach").count' do 153 assert_difference 'NodeAction.count', 1 do
140 post :create, params: { asset: { name: 'Logged twice' }, node_id: node.id } 154 post :create, params: { asset: { name: 'Logged once' }, node_id: node.id }
141 end
142 end 155 end
143 assert_equal users(:quentin), NodeAction.last.user 156
157 action = NodeAction.last
158 assert_equal "asset_create", action.action
159 assert_equal users(:quentin), action.user
144 end 160 end
145 161
146 # --- edit --- 162 # --- edit ---