diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-17 22:30:37 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-17 22:30:37 +0200 |
| commit | 24d61c40786497d864c7c8843e68cf2af880e5f7 (patch) | |
| tree | 17f9247d251ad513687c169237b79b78302bd094 /test | |
| parent | 1374ab51138a00024b0fe148394dbe4ea7f91578 (diff) | |
Bootstrap the Trash node: reserved slug, identity, guards
Diffstat (limited to 'test')
| -rw-r--r-- | test/models/node_test.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/models/node_test.rb b/test/models/node_test.rb index 9c4834e..3fb2d23 100644 --- a/test/models/node_test.rb +++ b/test/models/node_test.rb | |||
| @@ -807,4 +807,58 @@ class NodeTest < ActiveSupport::TestCase | |||
| 807 | 807 | ||
| 808 | assert_equal 0, Page.where(:id => autosave_id).count | 808 | assert_equal 0, Page.where(:id => autosave_id).count |
| 809 | end | 809 | end |
| 810 | |||
| 811 | test "Node.trash lazily creates the container exactly once" do | ||
| 812 | assert_difference "Node.count", 1 do | ||
| 813 | Node.trash | ||
| 814 | end | ||
| 815 | assert_no_difference "Node.count" do | ||
| 816 | assert_equal Node.trash, Node.trash | ||
| 817 | end | ||
| 818 | assert Node.trash.trash_node? | ||
| 819 | assert_not Node.trash.in_trash? | ||
| 820 | end | ||
| 821 | |||
| 822 | test "in_trash? walks the whole parent chain" do | ||
| 823 | child = Node.trash.children.create!(:slug => "trashed_thing") | ||
| 824 | grandchild = child.children.create!(:slug => "trashed_deeper") | ||
| 825 | |||
| 826 | assert child.in_trash? | ||
| 827 | assert grandchild.in_trash? | ||
| 828 | assert_not Node.root.children.create!(:slug => "living_thing").in_trash? | ||
| 829 | end | ||
| 830 | |||
| 831 | test "the reserved slug is refused for other root children, live and staged" do | ||
| 832 | Node.trash | ||
| 833 | |||
| 834 | assert_not Node.root.children.build(:slug => CccConventions::TRASH_SLUG).valid? | ||
| 835 | assert_not Node.root.children.build(:slug => "fine", :staged_slug => CccConventions::TRASH_SLUG).valid? | ||
| 836 | assert Node.trash.children.create!(:slug => "sub").children.build(:slug => CccConventions::TRASH_SLUG).valid? | ||
| 837 | end | ||
| 838 | |||
| 839 | test "the Trash node refuses rename, move, and destroy" do | ||
| 840 | trash = Node.trash | ||
| 841 | other = Node.root.children.create!(:slug => "not_the_trash") | ||
| 842 | |||
| 843 | trash.slug = "recycling" | ||
| 844 | assert_not trash.valid? | ||
| 845 | |||
| 846 | trash.reload.parent_id = other.id | ||
| 847 | assert_not trash.valid? | ||
| 848 | |||
| 849 | assert_no_difference "Node.count" do | ||
| 850 | assert_not trash.reload.destroy | ||
| 851 | end | ||
| 852 | end | ||
| 853 | |||
| 854 | test "a head cannot exist inside the Trash, and publishing there is refused" do | ||
| 855 | node = Node.trash.children.create!(:slug => "no_publish_here") | ||
| 856 | page = node.pages.create! | ||
| 857 | |||
| 858 | node.head = page | ||
| 859 | assert_not node.valid? | ||
| 860 | |||
| 861 | node.reload | ||
| 862 | assert_raises(ActiveRecord::RecordInvalid) { node.publish_draft! } | ||
| 863 | end | ||
| 810 | end | 864 | end |
