summaryrefslogtreecommitdiff
path: root/test/models/node_test.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-08 17:31:15 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-08 17:31:15 +0200
commit6ad96c44d04df01e6abde097c681e824dd5fe745 (patch)
treee90fcd5f3a4544bf2fd9ddf70530a82ac37b31c0 /test/models/node_test.rb
parent087fa345853a103844375892fa0405c1c241ea92 (diff)
Fix authorship and published_at loss in autosave promotion
Two real bugs surfaced by the full test suite, not by the new tests written for this feature -- both were latent the moment lock_for_editing! and save_draft! replaced find_or_create_draft, and only visible once an existing test exercised the exact path each one lived in. lock_for_editing! never stamped user/editor onto a draft that already existed when the lock was acquired. find_or_create_draft used to do this as part of acquiring the lock; splitting lock acquisition from draft creation dropped it entirely, since it looked like draft-creation logic rather than locking logic. Restored as an explicit step: claim authorship only if none is set yet, editorship unconditionally, matching the old behavior exactly. save_draft!'s "no draft yet" branch set user/editor before calling clone_attributes_from, whose first line is an unconditional self.reload -- silently discarding both, since neither had been persisted yet. clone_attributes_from also always copies published_at from its source without the ||= guard used for template_name, and the source here is always the autosave, whose published_at is never anything but nil -- meaning every single promotion, not just the first, was quietly resetting a published page's published_at, which publish_draft!'s own ||= Time.now would then treat as never-published and re-stamp. Fixed by running clone_attributes_from first on both branches, then applying user/editor/published_at afterward, exactly as the existing-draft branch already happened to do by accident. Four controller tests updated to insert a real put :update between get :edit and assertions that used to be true immediately after visiting edit -- deferred draft creation means edit alone no longer produces one, which is the intended consequence of this whole redesign, not something these tests were meant to catch.
Diffstat (limited to 'test/models/node_test.rb')
-rw-r--r--test/models/node_test.rb3
1 files changed, 3 insertions, 0 deletions
diff --git a/test/models/node_test.rb b/test/models/node_test.rb
index 2953f8f..bdf556d 100644
--- a/test/models/node_test.rb
+++ b/test/models/node_test.rb
@@ -339,6 +339,9 @@ class NodeTest < ActiveSupport::TestCase
339 assert_equal head_revision, node.head.revision 339 assert_equal head_revision, node.head.revision
340 assert_nil node.autosave 340 assert_nil node.autosave
341 assert_equal 2, node.pages.count 341 assert_equal 2, node.pages.count
342 assert_equal node.head.user, node.draft.user
343 assert_equal @user1, node.draft.editor
344 assert_equal node.head.published_at, node.draft.published_at
342 end 345 end
343 346
344 test "autosave!, save_draft!, and lock_for_editing! raise LockedByAnotherUser for a second user" do 347 test "autosave!, save_draft!, and lock_for_editing! raise LockedByAnotherUser for a second user" do