From 616a0d2d2ba15a7e176938ee829d60366fb6a9c2 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sun, 9 Aug 2026 13:26:23 +0200 Subject: Attach an asset to a page from the asset's own page The picker moves from assets/edit to assets/show, where the list of attached pages already is. A member route, POST assets/:id/attach_to_node, replaces the ride on #update. Supersedes the picker wiring in the previous commit; what remains of it is @attach_node in #create, the flash composition and the corrected hint. --- test/controllers/assets_controller_test.rb | 34 ++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/controllers/assets_controller_test.rb b/test/controllers/assets_controller_test.rb index c2d7ad57..67f629d9 100644 --- a/test/controllers/assets_controller_test.rb +++ b/test/controllers/assets_controller_test.rb @@ -163,19 +163,6 @@ class AssetsControllerTest < ActionController::TestCase assert_equal users(:quentin), action.user end - test "update with node_id attaches the asset to the node's draft" do - node = Node.root.children.create!(:slug => "asset_update_attach") - asset = Asset.create!(:name => "Existing", :upload_content_type => "image/png") - - put :update, params: { id: asset.id, asset: { name: "Existing" }, node_id: node.id } - - assert_response :redirect - assert_includes node.draft.assets.reload, asset - assert_equal [I18n.t("flash.assets.updated"), - I18n.t("flash.assets.attached_to_draft", :title => node.title)].join(" "), - flash[:notice] - end - # --- edit --- test "get edit" do @@ -235,6 +222,27 @@ class AssetsControllerTest < ActionController::TestCase assert_equal users(:quentin), NodeAction.last.user end + test "attach_to_node attaches the asset to the node's draft" do + node = Node.root.children.create!(:slug => "asset_show_attach") + asset = Asset.create!(:name => "From the asset page", :upload_content_type => "image/png") + + post :attach_to_node, params: { id: asset.id, node_id: node.id } + + assert_redirected_to asset_path(asset) + assert_includes node.draft.assets.reload, asset + assert_equal I18n.t("flash.assets.attached_to_draft", :title => node.title), flash[:notice] + end + + test "attach_to_node without a node says so and attaches nothing" do + asset = Asset.create!(:name => "Unpicked", :upload_content_type => "image/png") + + post :attach_to_node, params: { id: asset.id } + + assert_redirected_to asset_path(asset) + assert_equal I18n.t("flash.assets.attach_no_node"), flash[:error] + assert_empty asset.related_assets.reload + end + # --- URL helpers --- test "upload url returns correct path for original" do -- cgit v1.3