summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/models/node_action_test.rb9
-rw-r--r--test/models/node_test.rb52
2 files changed, 56 insertions, 5 deletions
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
59 assert_nil NodeAction.head_diff(old_page, build_page(:template_name => "standard_template"))[:template_changed] 59 assert_nil NodeAction.head_diff(old_page, build_page(:template_name => "standard_template"))[:template_changed]
60 end 60 end
61 61
62 test "assets_changed flag when the attached set differs" do 62 test "asset delta when the attached set differs" do
63 asset = Asset.create!(:name => "diff probe", 63 asset = Asset.create!(:name => "diff probe",
64 :upload_file_name => "test_image.png", 64 :upload_file_name => "test_image.png",
65 :upload_content_type => "image/png", 65 :upload_content_type => "image/png",
@@ -68,10 +68,9 @@ class NodeActionTest < ActiveSupport::TestCase
68 old_page, new_page = build_page, build_page 68 old_page, new_page = build_page, build_page
69 new_page.related_assets.create!(:asset_id => asset.id, :position => 1) 69 new_page.related_assets.create!(:asset_id => asset.id, :position => 1)
70 70
71 71 diff = NodeAction.head_diff(old_page, new_page)
72 diff = NodeAction.head_diff(old_page, new_page.reload) 72 assert diff[:assets].present?
73 assert diff[:assets_changed] 73 assert_nil NodeAction.head_diff(old_page, old_page)[:assets]
74 assert_nil NodeAction.head_diff(old_page, old_page)[:assets_changed]
75 end 74 end
76 75
77 test "default-locale abstract and body changes become flags, only when true" do 76 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
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") }