summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/node.rb10
-rw-r--r--test/models/node_trash_test.rb10
2 files changed, 19 insertions, 1 deletions
diff --git a/app/models/node.rb b/app/models/node.rb
index 8d0756a..19669ca 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -35,6 +35,14 @@ class Node < ApplicationRecord
35 :allow_nil => true, 35 :allow_nil => true,
36 :if => :default_template_name_changed? 36 :if => :default_template_name_changed?
37 37
38 # Everything outside the Trash subtree, the Trash node included.
39 # Relies on unique_name being authoritative for tree position --
40 # the same trust public routing places in it.
41 scope :not_in_trash, -> {
42 where.not(:unique_name => CccConventions::TRASH_SLUG)
43 .where("unique_name NOT LIKE ?", "#{CccConventions::TRASH_SLUG}/%")
44 }
45
38 # Class methods 46 # Class methods
39 47
40 # Returns a page for a given node. If no revision is supplied, it returns 48 # Returns a page for a given node. If no revision is supplied, it returns
@@ -504,7 +512,7 @@ class Node < ApplicationRecord
504 end 512 end
505 513
506 def self.drafts_and_autosaves(current_user_id: nil) 514 def self.drafts_and_autosaves(current_user_id: nil)
507 scope = where("draft_id IS NOT NULL OR autosave_id IS NOT NULL") 515 scope = where("draft_id IS NOT NULL OR autosave_id IS NOT NULL").not_in_trash
508 return scope.order("updated_at DESC") unless current_user_id 516 return scope.order("updated_at DESC") unless current_user_id
509 517
510 scope.order( 518 scope.order(
diff --git a/test/models/node_trash_test.rb b/test/models/node_trash_test.rb
index 07e5bc6..52069d7 100644
--- a/test/models/node_trash_test.rb
+++ b/test/models/node_trash_test.rb
@@ -155,4 +155,14 @@ class NodeTrashTest < ActiveSupport::TestCase
155 155
156 assert_equal Node.root, node.reload.suggested_restore_parent 156 assert_equal Node.root, node.reload.suggested_restore_parent
157 end 157 end
158
159 test "trashed nodes and the Trash itself stay out of the drafts surfaces" do
160 Node.trash
161 node = create_node_with_published_page
162 node.trash!(@user1)
163
164 ids = Node.drafts_and_autosaves.pluck(:id)
165 assert_not_includes ids, Node.trash.id
166 assert_not_includes ids, node.id
167 end
158end 168end