diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-08-09 13:26:23 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-08-09 13:26:23 +0200 |
| commit | 616a0d2d2ba15a7e176938ee829d60366fb6a9c2 (patch) | |
| tree | fe12e0ab804948f0e3ff37636859b05cef7871cc /test/controllers | |
| parent | 42b996e9197680a1955cfa5639462908677e5a94 (diff) | |
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.
Diffstat (limited to 'test/controllers')
| -rw-r--r-- | test/controllers/assets_controller_test.rb | 34 |
1 files changed, 21 insertions, 13 deletions
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 | |||
| 163 | assert_equal users(:quentin), action.user | 163 | assert_equal users(:quentin), action.user |
| 164 | end | 164 | end |
| 165 | 165 | ||
| 166 | test "update with node_id attaches the asset to the node's draft" do | ||
| 167 | node = Node.root.children.create!(:slug => "asset_update_attach") | ||
| 168 | asset = Asset.create!(:name => "Existing", :upload_content_type => "image/png") | ||
| 169 | |||
| 170 | put :update, params: { id: asset.id, asset: { name: "Existing" }, node_id: node.id } | ||
| 171 | |||
| 172 | assert_response :redirect | ||
| 173 | assert_includes node.draft.assets.reload, asset | ||
| 174 | assert_equal [I18n.t("flash.assets.updated"), | ||
| 175 | I18n.t("flash.assets.attached_to_draft", :title => node.title)].join(" "), | ||
| 176 | flash[:notice] | ||
| 177 | end | ||
| 178 | |||
| 179 | # --- edit --- | 166 | # --- edit --- |
| 180 | 167 | ||
| 181 | test "get edit" do | 168 | test "get edit" do |
| @@ -235,6 +222,27 @@ class AssetsControllerTest < ActionController::TestCase | |||
| 235 | assert_equal users(:quentin), NodeAction.last.user | 222 | assert_equal users(:quentin), NodeAction.last.user |
| 236 | end | 223 | end |
| 237 | 224 | ||
| 225 | test "attach_to_node attaches the asset to the node's draft" do | ||
| 226 | node = Node.root.children.create!(:slug => "asset_show_attach") | ||
| 227 | asset = Asset.create!(:name => "From the asset page", :upload_content_type => "image/png") | ||
| 228 | |||
| 229 | post :attach_to_node, params: { id: asset.id, node_id: node.id } | ||
| 230 | |||
| 231 | assert_redirected_to asset_path(asset) | ||
| 232 | assert_includes node.draft.assets.reload, asset | ||
| 233 | assert_equal I18n.t("flash.assets.attached_to_draft", :title => node.title), flash[:notice] | ||
| 234 | end | ||
| 235 | |||
| 236 | test "attach_to_node without a node says so and attaches nothing" do | ||
| 237 | asset = Asset.create!(:name => "Unpicked", :upload_content_type => "image/png") | ||
| 238 | |||
| 239 | post :attach_to_node, params: { id: asset.id } | ||
| 240 | |||
| 241 | assert_redirected_to asset_path(asset) | ||
| 242 | assert_equal I18n.t("flash.assets.attach_no_node"), flash[:error] | ||
| 243 | assert_empty asset.related_assets.reload | ||
| 244 | end | ||
| 245 | |||
| 238 | # --- URL helpers --- | 246 | # --- URL helpers --- |
| 239 | 247 | ||
| 240 | test "upload url returns correct path for original" do | 248 | test "upload url returns correct path for original" do |
