From f993853db3e233f05a55de5ba2a87b77acf041aa Mon Sep 17 00:00:00 2001 From: erdgeist Date: Thu, 23 Jul 2026 17:49:18 +0200 Subject: Record asset deltas at publish, with changed assets as participants --- test/models/node_action_test.rb | 9 ++++--- test/models/node_test.rb | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/models/node_action_test.rb b/test/models/node_action_test.rb index 849b36f4..4672456a 100644 --- a/test/models/node_action_test.rb +++ b/test/models/node_action_test.rb @@ -59,7 +59,7 @@ class NodeActionTest < ActiveSupport::TestCase assert_nil NodeAction.head_diff(old_page, build_page(:template_name => "standard_template"))[:template_changed] end - test "assets_changed flag when the attached set differs" do + test "asset delta when the attached set differs" do asset = Asset.create!(:name => "diff probe", :upload_file_name => "test_image.png", :upload_content_type => "image/png", @@ -68,10 +68,9 @@ class NodeActionTest < ActiveSupport::TestCase old_page, new_page = build_page, build_page new_page.related_assets.create!(:asset_id => asset.id, :position => 1) - - diff = NodeAction.head_diff(old_page, new_page.reload) - assert diff[:assets_changed] - assert_nil NodeAction.head_diff(old_page, old_page)[:assets_changed] + diff = NodeAction.head_diff(old_page, new_page) + assert diff[:assets].present? + assert_nil NodeAction.head_diff(old_page, old_page)[:assets] end test "default-locale abstract and body changes become flags, only when true" do diff --git a/test/models/node_test.rb b/test/models/node_test.rb index 0083b088..8bdb90ee 100644 --- a/test/models/node_test.rb +++ b/test/models/node_test.rb @@ -728,6 +728,58 @@ class NodeTest < ActiveSupport::TestCase NodeAction.order(:id).last(2).map(&:action).sort end + test "publish records the asset delta with changed assets as participants" do + node = Node.root.children.create!(:slug => "publish_asset_delta") + kept = Asset.create!(:name => "Kept", :upload_content_type => "image/png") + added = Asset.create!(:name => "Added", :upload_content_type => "image/png") + node.draft.related_assets.create!(:asset => kept) + node.publish_draft!(@user1) + + node.lock_for_editing!(@user1) + node.create_new_draft(@user1) + node.draft.related_assets.create!(:asset => added) + node.publish_draft!(@user1) + + action = node.node_actions.where(:action => "publish").order(:id).last + assert_equal ["Added"], action.metadata.dig("assets", "added") + assert_nil action.metadata.dig("assets", "removed") + subjects = action.action_participants.map { |p| [p.subject_type, p.subject_id] } + assert_includes subjects, ["Asset", added.id] + assert_not_includes subjects, ["Asset", kept.id] + end + + test "publish without an asset change writes no assets key" do + node = Node.root.children.create!(:slug => "publish_asset_static") + node.draft.related_assets.create!(:asset => Asset.create!(:name => "Steady")) + node.publish_draft!(@user1) + + node.lock_for_editing!(@user1) + node.create_new_draft(@user1) + node.publish_draft!(@user1) + + action = node.node_actions.where(:action => "publish").order(:id).last + assert_nil action.metadata["assets"] + assert_equal [["Node", node.id]], + action.action_participants.map { |p| [p.subject_type, p.subject_id] } + end + + test "pure reordering is recorded as assets_reordered" do + node = Node.root.children.create!(:slug => "publish_asset_reorder") + a1, a2 = Asset.create!(:name => "First"), Asset.create!(:name => "Second") + node.draft.related_assets.create!(:asset => a1) + node.draft.related_assets.create!(:asset => a2) + node.publish_draft!(@user1) + + node.lock_for_editing!(@user1) + node.create_new_draft(@user1) + node.draft.related_assets.reload.first.move_to_bottom + node.publish_draft!(@user1) + + action = node.node_actions.where(:action => "publish").order(:id).last + assert action.metadata["assets_reordered"] + assert_nil action.metadata["assets"] + end + test "restore_revision! logs a publish via revision" do node = create_node_with_published_page Globalize.with_locale(:de) { node.head.update!(:title => "First") } -- cgit v1.3