diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-08 17:31:15 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-08 17:31:15 +0200 |
| commit | 6ad96c44d04df01e6abde097c681e824dd5fe745 (patch) | |
| tree | e90fcd5f3a4544bf2fd9ddf70530a82ac37b31c0 /test/controllers/nodes_controller_test.rb | |
| parent | 087fa345853a103844375892fa0405c1c241ea92 (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/controllers/nodes_controller_test.rb')
| -rw-r--r-- | test/controllers/nodes_controller_test.rb | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb index 030cff0..f3e04c2 100644 --- a/test/controllers/nodes_controller_test.rb +++ b/test/controllers/nodes_controller_test.rb | |||
| @@ -101,7 +101,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 101 | assert_select("#page_body", "World") | 101 | assert_select("#page_body", "World") |
| 102 | 102 | ||
| 103 | node.reload | 103 | node.reload |
| 104 | assert_equal 2, node.pages.length | 104 | assert_equal 1, node.pages.length |
| 105 | assert_equal "Hello", node.find_or_create_draft( User.first ).title | 105 | assert_equal "Hello", node.find_or_create_draft( User.first ).title |
| 106 | assert_equal "World", node.find_or_create_draft( User.first ).body | 106 | assert_equal "World", node.find_or_create_draft( User.first ).body |
| 107 | end | 107 | end |
| @@ -291,6 +291,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 291 | get :edit, params: { :id => node.id } | 291 | get :edit, params: { :id => node.id } |
| 292 | assert_response :success | 292 | assert_response :success |
| 293 | 293 | ||
| 294 | put :update, params: { :id => node.id, :page => { :title => "updated" } } | ||
| 294 | put :publish, params: { :id => node.id } | 295 | put :publish, params: { :id => node.id } |
| 295 | 296 | ||
| 296 | node.reload | 297 | node.reload |
| @@ -303,6 +304,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 303 | node = create_node_with_published_page | 304 | node = create_node_with_published_page |
| 304 | get :edit, params: { :id => node.id } | 305 | get :edit, params: { :id => node.id } |
| 305 | 306 | ||
| 307 | put :update, params: { :id => node.id, :page => { :title => "updated" } } | ||
| 306 | put :publish, params: { :id => node.id } | 308 | put :publish, params: { :id => node.id } |
| 307 | 309 | ||
| 308 | node.reload | 310 | node.reload |
| @@ -324,7 +326,8 @@ class NodesControllerTest < ActionController::TestCase | |||
| 324 | assert_equal "quentin", node.head.user.login | 326 | assert_equal "quentin", node.head.user.login |
| 325 | 327 | ||
| 326 | login_as :aaron | 328 | login_as :aaron |
| 327 | get :edit, params: {:id => node.id } | 329 | get :edit, params: { :id => node.id } |
| 330 | put :update, params: { :id => node.id, :page => { :title => "updated" } } | ||
| 328 | 331 | ||
| 329 | node.reload | 332 | node.reload |
| 330 | assert_equal "quentin", node.head.user.login | 333 | assert_equal "quentin", node.head.user.login |
