summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-17 23:14:17 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-17 23:14:17 +0200
commit5dced8b4b624aabf4215ba21b13957080345c326 (patch)
tree70afdbd65f28309da76b60e084aad05776ec1881 /test
parent2748dc23be86eeb1e4f5e155b8f2191245bb5f5c (diff)
Route and control trash, restore, and permanent deletion
Diffstat (limited to 'test')
-rw-r--r--test/controllers/nodes_controller_test.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb
index b0d7416..7e5a990 100644
--- a/test/controllers/nodes_controller_test.rb
+++ b/test/controllers/nodes_controller_test.rb
@@ -672,4 +672,56 @@ class NodesControllerTest < ActionController::TestCase
672 assert_equal "Brand New", action.metadata["title"] 672 assert_equal "Brand New", action.metadata["title"]
673 assert_equal Node.last.unique_name, action.metadata["path"] 673 assert_equal Node.last.unique_name, action.metadata["path"]
674 end 674 end
675
676 test "trash moves the node and redirects to the Trash" do
677 login_as :quentin
678 node = Node.root.children.create!(:slug => "trash_me")
679
680 put :trash, params: { :id => node.id }
681
682 assert_redirected_to node_path(Node.trash)
683 assert node.reload.in_trash?
684 end
685
686 test "trashing the Trash node itself is refused" do
687 login_as :quentin
688
689 put :trash, params: { :id => Node.trash.id }
690
691 assert_redirected_to node_path(Node.trash)
692 assert flash[:error].present?
693 end
694
695 test "restore_from_trash reparents to the given parent" do
696 login_as :quentin
697 node = Node.root.children.create!(:slug => "restore_me")
698 node.trash!(users(:quentin))
699 target = Node.root.children.create!(:slug => "restore_home")
700
701 put :restore_from_trash, params: { :id => node.id, :parent_id => target.id }
702
703 assert_redirected_to node_path(node)
704 assert_equal target, node.reload.parent
705 end
706
707 test "destroy refuses a node outside the Trash" do
708 login_as :quentin
709 node = Node.root.children.create!(:slug => "not_deletable_here")
710
711 delete :destroy, params: { :id => node.id }
712
713 assert Node.exists?(node.id)
714 assert flash[:error].present?
715 end
716
717 test "destroy deletes a trashed node and redirects to the Trash" do
718 login_as :quentin
719 node = Node.root.children.create!(:slug => "deletable")
720 node.trash!(users(:quentin))
721
722 delete :destroy, params: { :id => node.id }
723
724 assert_not Node.exists?(node.id)
725 assert_redirected_to node_path(Node.trash)
726 end
675end 727end