From 42b996e9197680a1955cfa5639462908677e5a94 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sun, 9 Aug 2026 04:14:30 +0200 Subject: Attach an asset to a page from its edit form --- test/controllers/assets_controller_test.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'test/controllers') diff --git a/test/controllers/assets_controller_test.rb b/test/controllers/assets_controller_test.rb index aa3e00e6..c2d7ad57 100644 --- a/test/controllers/assets_controller_test.rb +++ b/test/controllers/assets_controller_test.rb @@ -102,7 +102,9 @@ class AssetsControllerTest < ActionController::TestCase assert_response :redirect asset = Asset.last assert_includes node.draft.assets.reload, asset - assert_equal I18n.t("flash.assets.attached_to_draft", :title => node.title), flash[:notice] + assert_equal [I18n.t("flash.assets.created"), + I18n.t("flash.assets.attached_to_draft", :title => node.title)].join(" "), + flash[:notice] end test "create with node_id creates a draft when none is pending" do @@ -116,7 +118,9 @@ class AssetsControllerTest < ActionController::TestCase assert_includes node.draft.assets.reload, Asset.last assert_empty node.head.assets.reload assert_equal users(:quentin), node.draft.editor - assert_equal I18n.t("flash.assets.attached_new_draft", :title => node.title), flash[:notice] + assert_equal [I18n.t("flash.assets.created"), + I18n.t("flash.assets.attached_new_draft", :title => node.title)].join(" "), + flash[:notice] end test "create against a foreign-locked node keeps the asset but refuses the attach" do @@ -159,6 +163,19 @@ 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 -- cgit v1.3