summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-06 13:52:28 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-06 13:52:28 +0200
commit889e15eabbe107d2642fdd8aa3f03821058c00dc (patch)
tree5016fbf2fd673063c90608ae36406bd350dd34a2 /test
parent9e63a6bec1b4ccc45dd684f7b6a941b75f9b9cf0 (diff)
Fix shared preview links breaking after a second publish
A token's page could stop being node.head_id (superseded by a newer draft) while still being published_at.present? - the old check only compared against the current head, so a superseded page fell through to direct rendering instead of redirecting, serving a stale frozen snapshot indefinitely instead of the current live content. Also handles scheduled publishing correctly: a page can be head_id but not yet public? (published_at in the future) - that case must still render directly, not redirect into a 404 on the not-yet-live public URL.
Diffstat (limited to 'test')
-rw-r--r--test/models/page_test.rb35
1 files changed, 34 insertions, 1 deletions
diff --git a/test/models/page_test.rb b/test/models/page_test.rb
index afba8b5..ad2742f 100644
--- a/test/models/page_test.rb
+++ b/test/models/page_test.rb
@@ -142,5 +142,38 @@ class PageTest < ActiveSupport::TestCase
142 update = updates2009.children.create!( :slug => "my-first-update" ) 142 update = updates2009.children.create!( :slug => "my-first-update" )
143 assert_equal "update", update.draft.template_name 143 assert_equal "update", update.draft.template_name
144 end 144 end
145 145
146 test "a page scheduled for future publication is not yet public even after being published" do
147 node = Node.root.children.create!(slug: "preview-scheduled-test")
148 draft = node.find_or_create_draft(@user1)
149 draft.title = "Scheduled test"
150 draft.published_at = 1.day.from_now
151 draft.save!
152 token = draft.ensure_preview_token!
153
154 node.publish_draft!
155 page = Page.find_by(preview_token: token)
156
157 assert_equal page.id, page.node.head_id
158 assert_not page.public?
159 end
160
161 test "a superseded page is no longer the head, even though it was once published" do
162 node = Node.root.children.create!(slug: "preview-superseded-test")
163 first_draft = node.find_or_create_draft(@user1)
164 first_draft.title = "First version"
165 first_draft.save!
166 first_token = first_draft.ensure_preview_token!
167 node.publish_draft!
168
169 second_draft = node.find_or_create_draft(@user1)
170 second_draft.title = "Second version"
171 second_draft.save!
172 node.publish_draft!
173
174 first_page = Page.find_by(preview_token: first_token)
175
176 assert_not_equal first_page.id, first_page.node.head_id
177 assert first_page.published_at.present?
178 end
146end 179end