diff options
Diffstat (limited to 'test/models')
| -rw-r--r-- | test/models/node_action_test.rb | 20 | ||||
| -rw-r--r-- | test/models/node_test.rb | 10 |
2 files changed, 29 insertions, 1 deletions
diff --git a/test/models/node_action_test.rb b/test/models/node_action_test.rb index b177cca..849b36f 100644 --- a/test/models/node_action_test.rb +++ b/test/models/node_action_test.rb | |||
| @@ -118,11 +118,29 @@ class NodeActionTest < ActiveSupport::TestCase | |||
| 118 | 118 | ||
| 119 | test "record! passes provenance and historical timestamps through" do | 119 | test "record! passes provenance and historical timestamps through" do |
| 120 | long_ago = 2.years.ago | 120 | long_ago = 2.years.ago |
| 121 | action = NodeAction.record!(:node => nil, :action => "publish", | 121 | node = Node.root.children.create!(:slug => "provenance_backfill_test") |
| 122 | action = NodeAction.record!(:node => node, :action => "publish", | ||
| 122 | :occurred_at => long_ago, | 123 | :occurred_at => long_ago, |
| 123 | :inferred_from => "from_page_revision") | 124 | :inferred_from => "from_page_revision") |
| 124 | 125 | ||
| 125 | assert_equal "from_page_revision", action.inferred_from | 126 | assert_equal "from_page_revision", action.inferred_from |
| 126 | assert_in_delta long_ago.to_f, action.occurred_at.to_f, 1.0 | 127 | assert_in_delta long_ago.to_f, action.occurred_at.to_f, 1.0 |
| 127 | end | 128 | end |
| 129 | |||
| 130 | |||
| 131 | test "record! with participants: writes one action_participant per subject" do | ||
| 132 | n1, n2 = Node.root.children.create!(:slug => "participant_a"), Node.root.children.create!(:slug => "participant_b") | ||
| 133 | action = NodeAction.record!(:participants => [n1, n2], :action => "trash", :user => users(:quentin)) | ||
| 134 | assert_equal [n1, n2], action.action_participants.map(&:subject) | ||
| 135 | end | ||
| 136 | |||
| 137 | test "record! with node: alone still writes exactly one participant" do | ||
| 138 | node = Node.root.children.create!(:slug => "participant_sugar") | ||
| 139 | action = NodeAction.record!(:node => node, :action => "create", :user => users(:quentin)) | ||
| 140 | assert_equal [node], action.action_participants.map(&:subject) | ||
| 141 | end | ||
| 142 | |||
| 143 | test "record! refuses an empty participant set" do | ||
| 144 | assert_raises(ArgumentError) { NodeAction.record!(:action => "create", :user => users(:quentin)) } | ||
| 145 | end | ||
| 128 | end | 146 | end |
diff --git a/test/models/node_test.rb b/test/models/node_test.rb index ba38340..0083b08 100644 --- a/test/models/node_test.rb +++ b/test/models/node_test.rb | |||
| @@ -756,6 +756,16 @@ class NodeTest < ActiveSupport::TestCase | |||
| 756 | assert node.valid? | 756 | assert node.valid? |
| 757 | end | 757 | end |
| 758 | 758 | ||
| 759 | test "trash! records every subtree node as a participant, not just the root" do | ||
| 760 | parent = Node.root.children.create!(:slug => "trash_participants_parent") | ||
| 761 | child = parent.children.create!(:slug => "trash_participants_child") | ||
| 762 | |||
| 763 | parent.trash!(users(:quentin)) | ||
| 764 | |||
| 765 | action = parent.node_actions.where(:action => "trash").last | ||
| 766 | assert_includes action.action_participants.map(&:subject), child | ||
| 767 | end | ||
| 768 | |||
| 759 | test "destroying a node with children is refused" do | 769 | test "destroying a node with children is refused" do |
| 760 | parent = Node.root.children.create!(:slug => "destroy_guard_parent") | 770 | parent = Node.root.children.create!(:slug => "destroy_guard_parent") |
| 761 | parent.children.create!(:slug => "destroy_guard_child") | 771 | parent.children.create!(:slug => "destroy_guard_child") |
