diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 04:54:33 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 04:54:33 +0200 |
| commit | 8baac265059b70da0148487458ee4077b15f155e (patch) | |
| tree | b97b07a76bec2fef602fa01c1739a89a412d812f /test/models/node_test.rb | |
| parent | b138f40a6493f7c4341fba196c48440e795babb9 (diff) | |
Asset picker: attach/detach/reorder UI, read-only view, autosave fix
Replaces nodes#edit's old Images section -- a hidden panel dumping
every image asset in the system unfiltered (#image_browser) plus a
raw drag-and-drop box (#image_box) -- with a small search-and-click
picker built on the endpoint from the last two commits. Attaching
posts immediately and appends the new thumbnail via a cloned
<template> -- icons only render correctly through the Rails helper
server-side, so the template holds real, pre-rendered markup for JS
to clone rather than duplicating raw SVG in a JS string. Reordering is
jQuery UI sortable on the small attached list only, with a dedicated
drag handle rather than the whole thumbnail.
Two bugs caught while click-testing, fixed here rather than shipped
and patched after: the search panel never closed after attaching an
image, since the success handler re-triggered focus to keep it open
for attaching several in a row -- which meant it just re-populated
itself forever instead of signaling "done." Fixed to close explicitly;
a click-outside-closes handler was added alongside it, matching the
affordance the top-bar search already has.
A real, independent, pre-existing data bug surfaced during the same
testing: Node#autosave!'s first-time-creation branch never carried
related assets forward from whatever page was previously current --
attach an image, let autosave fire once, and it silently landed on a
fresh, assetless Page row. Long-dormant, not introduced by this work,
just finally exercised by something that made it visible. Fixed inside
the `unless self.autosave` guard specifically -- running this on every
call, not just creation, would overwrite anything attached directly to
an existing autosave in between, a worse bug than the one being fixed.
nodes#show gains a read-only Images section, rendered only when a page
actually has attached images, so an attachment can be confirmed
present without entering the edit/lock cycle -- useful on its own, and
specifically useful the next time an asset bug needs investigating.
Its thumbnail CSS is shared with the edit view's picker via a class
(.thumbnail_list) rather than duplicated under a second name.
Diffstat (limited to 'test/models/node_test.rb')
| -rw-r--r-- | test/models/node_test.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/models/node_test.rb b/test/models/node_test.rb index 0bce222..a1da82c 100644 --- a/test/models/node_test.rb +++ b/test/models/node_test.rb | |||
| @@ -585,4 +585,33 @@ class NodeTest < ActiveSupport::TestCase | |||
| 585 | 585 | ||
| 586 | assert_not_includes Node.recently_changed, node | 586 | assert_not_includes Node.recently_changed, node |
| 587 | end | 587 | end |
| 588 | |||
| 589 | test "autosave! carries over the current related assets to the newly created autosave row" do | ||
| 590 | node = Node.root.children.create!(:slug => "autosave_asset_carryover_test") | ||
| 591 | user = User.find_by_login("quentin") | ||
| 592 | asset = Asset.create!(:name => "carryover-photo", :upload_content_type => "image/png") | ||
| 593 | node.draft.assets << asset | ||
| 594 | |||
| 595 | node.lock_for_editing!(user) | ||
| 596 | node.autosave!({:title => "v1"}, user) | ||
| 597 | |||
| 598 | assert_includes node.autosave.reload.assets, asset | ||
| 599 | end | ||
| 600 | |||
| 601 | test "autosave! does not reset assets already attached directly to an existing autosave" do | ||
| 602 | node = Node.root.children.create!(:slug => "autosave_asset_no_reset_test") | ||
| 603 | user = User.find_by_login("quentin") | ||
| 604 | original = Asset.create!(:name => "original-photo", :upload_content_type => "image/png") | ||
| 605 | extra = Asset.create!(:name => "extra-photo", :upload_content_type => "image/png") | ||
| 606 | node.draft.assets << original | ||
| 607 | |||
| 608 | node.lock_for_editing!(user) | ||
| 609 | node.autosave!({:title => "v1"}, user) | ||
| 610 | node.autosave.assets << extra | ||
| 611 | |||
| 612 | node.autosave!({:title => "v2"}, user) | ||
| 613 | |||
| 614 | assert_includes node.autosave.reload.assets, original | ||
| 615 | assert_includes node.autosave.reload.assets, extra | ||
| 616 | end | ||
| 588 | end | 617 | end |
