From d9e95bdb6436768c738539df74a164c885887174 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Thu, 23 Jul 2026 03:28:55 +0200 Subject: Add action_participants, recording every node a trash/destroy touches --- test/models/node_action_test.rb | 20 +++++++++++++++++++- test/models/node_test.rb | 10 ++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'test/models') diff --git a/test/models/node_action_test.rb b/test/models/node_action_test.rb index b177ccac..849b36f4 100644 --- a/test/models/node_action_test.rb +++ b/test/models/node_action_test.rb @@ -118,11 +118,29 @@ class NodeActionTest < ActiveSupport::TestCase test "record! passes provenance and historical timestamps through" do long_ago = 2.years.ago - action = NodeAction.record!(:node => nil, :action => "publish", + node = Node.root.children.create!(:slug => "provenance_backfill_test") + action = NodeAction.record!(:node => node, :action => "publish", :occurred_at => long_ago, :inferred_from => "from_page_revision") assert_equal "from_page_revision", action.inferred_from assert_in_delta long_ago.to_f, action.occurred_at.to_f, 1.0 end + + + test "record! with participants: writes one action_participant per subject" do + n1, n2 = Node.root.children.create!(:slug => "participant_a"), Node.root.children.create!(:slug => "participant_b") + action = NodeAction.record!(:participants => [n1, n2], :action => "trash", :user => users(:quentin)) + assert_equal [n1, n2], action.action_participants.map(&:subject) + end + + test "record! with node: alone still writes exactly one participant" do + node = Node.root.children.create!(:slug => "participant_sugar") + action = NodeAction.record!(:node => node, :action => "create", :user => users(:quentin)) + assert_equal [node], action.action_participants.map(&:subject) + end + + test "record! refuses an empty participant set" do + assert_raises(ArgumentError) { NodeAction.record!(:action => "create", :user => users(:quentin)) } + end end diff --git a/test/models/node_test.rb b/test/models/node_test.rb index ba383405..0083b088 100644 --- a/test/models/node_test.rb +++ b/test/models/node_test.rb @@ -756,6 +756,16 @@ class NodeTest < ActiveSupport::TestCase assert node.valid? end + test "trash! records every subtree node as a participant, not just the root" do + parent = Node.root.children.create!(:slug => "trash_participants_parent") + child = parent.children.create!(:slug => "trash_participants_child") + + parent.trash!(users(:quentin)) + + action = parent.node_actions.where(:action => "trash").last + assert_includes action.action_participants.map(&:subject), child + end + test "destroying a node with children is refused" do parent = Node.root.children.create!(:slug => "destroy_guard_parent") parent.children.create!(:slug => "destroy_guard_child") -- cgit v1.3