summaryrefslogtreecommitdiff
path: root/test/models/node_test.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-23 17:49:18 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-23 17:49:18 +0200
commitf993853db3e233f05a55de5ba2a87b77acf041aa (patch)
tree0a28289ff471ab5853b22c2a68ed21ce4e0eb4ac /test/models/node_test.rb
parent932d4a4be40587fa6d489eca16a1ef6d6f2936d1 (diff)
Record asset deltas at publish, with changed assets as participants
Diffstat (limited to 'test/models/node_test.rb')
-rw-r--r--test/models/node_test.rb52
1 files changed, 52 insertions, 0 deletions
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
728 NodeAction.order(:id).last(2).map(&:action).sort 728 NodeAction.order(:id).last(2).map(&:action).sort
729 end 729 end
730 730
731 test "publish records the asset delta with changed assets as participants" do
732 node = Node.root.children.create!(:slug => "publish_asset_delta")
733 kept = Asset.create!(:name => "Kept", :upload_content_type => "image/png")
734 added = Asset.create!(:name => "Added", :upload_content_type => "image/png")
735 node.draft.related_assets.create!(:asset => kept)
736 node.publish_draft!(@user1)
737
738 node.lock_for_editing!(@user1)
739 node.create_new_draft(@user1)
740 node.draft.related_assets.create!(:asset => added)
741 node.publish_draft!(@user1)
742
743 action = node.node_actions.where(:action => "publish").order(:id).last
744 assert_equal ["Added"], action.metadata.dig("assets", "added")
745 assert_nil action.metadata.dig("assets", "removed")
746 subjects = action.action_participants.map { |p| [p.subject_type, p.subject_id] }
747 assert_includes subjects, ["Asset", added.id]
748 assert_not_includes subjects, ["Asset", kept.id]
749 end
750
751 test "publish without an asset change writes no assets key" do
752 node = Node.root.children.create!(:slug => "publish_asset_static")
753 node.draft.related_assets.create!(:asset => Asset.create!(:name => "Steady"))
754 node.publish_draft!(@user1)
755
756 node.lock_for_editing!(@user1)
757 node.create_new_draft(@user1)
758 node.publish_draft!(@user1)
759
760 action = node.node_actions.where(:action => "publish").order(:id).last
761 assert_nil action.metadata["assets"]
762 assert_equal [["Node", node.id]],
763 action.action_participants.map { |p| [p.subject_type, p.subject_id] }
764 end
765
766 test "pure reordering is recorded as assets_reordered" do
767 node = Node.root.children.create!(:slug => "publish_asset_reorder")
768 a1, a2 = Asset.create!(:name => "First"), Asset.create!(:name => "Second")
769 node.draft.related_assets.create!(:asset => a1)
770 node.draft.related_assets.create!(:asset => a2)
771 node.publish_draft!(@user1)
772
773 node.lock_for_editing!(@user1)
774 node.create_new_draft(@user1)
775 node.draft.related_assets.reload.first.move_to_bottom
776 node.publish_draft!(@user1)
777
778 action = node.node_actions.where(:action => "publish").order(:id).last
779 assert action.metadata["assets_reordered"]
780 assert_nil action.metadata["assets"]
781 end
782
731 test "restore_revision! logs a publish via revision" do 783 test "restore_revision! logs a publish via revision" do
732 node = create_node_with_published_page 784 node = create_node_with_published_page
733 Globalize.with_locale(:de) { node.head.update!(:title => "First") } 785 Globalize.with_locale(:de) { node.head.update!(:title => "First") }