diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-10 02:13:02 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-10 02:13:02 +0200 |
| commit | c2b2648d327e1c1749c37fe2e58cd051ed871547 (patch) | |
| tree | e8d3c48eb01b8d6b512d20603a1db8f910ec110c | |
| parent | 205e6216fc7850fe717122c189e5003d1f9e8afe (diff) | |
Destroying Draft or Discarding Autosave drops you where you left
| -rw-r--r-- | app/controllers/nodes_controller.rb | 5 | ||||
| -rw-r--r-- | app/views/nodes/show.html.erb | 1 | ||||
| -rw-r--r-- | app/views/revisions/diff.html.erb | 1 | ||||
| -rw-r--r-- | test/controllers/nodes_controller_test.rb | 39 |
4 files changed, 45 insertions, 1 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index d1538e1..6fcd930 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb | |||
| @@ -128,7 +128,10 @@ class NodesController < ApplicationController | |||
| 128 | def revert | 128 | def revert |
| 129 | @node.lock_for_editing!(current_user) | 129 | @node.lock_for_editing!(current_user) |
| 130 | @node.revert!(current_user) | 130 | @node.revert!(current_user) |
| 131 | if @node.draft | 131 | |
| 132 | if params[:return_to].present? | ||
| 133 | redirect_to safe_return_to(params[:return_to]) | ||
| 134 | elsif @node.draft | ||
| 132 | redirect_to edit_node_path(@node) | 135 | redirect_to edit_node_path(@node) |
| 133 | else | 136 | else |
| 134 | redirect_to node_path(@node) | 137 | redirect_to node_path(@node) |
diff --git a/app/views/nodes/show.html.erb b/app/views/nodes/show.html.erb index 2469310..8b9e98b 100644 --- a/app/views/nodes/show.html.erb +++ b/app/views/nodes/show.html.erb | |||
| @@ -53,6 +53,7 @@ | |||
| 53 | <div class="node_info_item"> | 53 | <div class="node_info_item"> |
| 54 | <%= button_to (@node.draft && !@node.autosave ? 'Destroy Draft' : 'Discard Autosave'), | 54 | <%= button_to (@node.draft && !@node.autosave ? 'Destroy Draft' : 'Discard Autosave'), |
| 55 | revert_node_path(@node), method: :put, | 55 | revert_node_path(@node), method: :put, |
| 56 | params: { return_to: request.path }, | ||
| 56 | form: { data: { confirm: "This cannot be undone. Continue?" }, class: 'button_to destructive' } %> | 57 | form: { data: { confirm: "This cannot be undone. Continue?" }, class: 'button_to destructive' } %> |
| 57 | </div> | 58 | </div> |
| 58 | <% end %> | 59 | <% end %> |
diff --git a/app/views/revisions/diff.html.erb b/app/views/revisions/diff.html.erb index 3157dca..490cf17 100644 --- a/app/views/revisions/diff.html.erb +++ b/app/views/revisions/diff.html.erb | |||
| @@ -36,6 +36,7 @@ | |||
| 36 | <% if !@locked_by_other && (@node.autosave || @node.draft) %> | 36 | <% if !@locked_by_other && (@node.autosave || @node.draft) %> |
| 37 | <%= button_to (@node.draft && !@node.autosave ? 'Destroy Draft' : 'Discard Autosave'), | 37 | <%= button_to (@node.draft && !@node.autosave ? 'Destroy Draft' : 'Discard Autosave'), |
| 38 | revert_node_path(@node), method: :put, | 38 | revert_node_path(@node), method: :put, |
| 39 | params: { return_to: request.fullpath }, | ||
| 39 | form: { data: { confirm: "This cannot be undone. Continue?" }, class: 'button_to destructive' } %> | 40 | form: { data: { confirm: "This cannot be undone. Continue?" }, class: 'button_to destructive' } %> |
| 40 | <% end %> | 41 | <% end %> |
| 41 | </p> | 42 | </p> |
diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb index f3e04c2..ce3419c 100644 --- a/test/controllers/nodes_controller_test.rb +++ b/test/controllers/nodes_controller_test.rb | |||
| @@ -423,4 +423,43 @@ class NodesControllerTest < ActionController::TestCase | |||
| 423 | assert_select "form.button_to.destructive", count: 0 | 423 | assert_select "form.button_to.destructive", count: 0 |
| 424 | end | 424 | end |
| 425 | 425 | ||
| 426 | test "reverting from nodes#show returns to the show page, not the editor, even if a draft remains" do | ||
| 427 | user = User.find_by_login("aaron") | ||
| 428 | node = Node.root.children.create!(:slug => "revert_return_to_test") | ||
| 429 | node.lock_for_editing!(user) | ||
| 430 | node.autosave!({:title => "v1"}, user) | ||
| 431 | node.save_draft!(user) | ||
| 432 | node.publish_draft! | ||
| 433 | node.lock_for_editing!(user) | ||
| 434 | node.autosave!({:title => "v2"}, user) | ||
| 435 | node.save_draft!(user) | ||
| 436 | node.lock_for_editing!(user) | ||
| 437 | node.autosave!({:title => "v3"}, user) | ||
| 438 | # state D: head, draft, and autosave all present, locked by aaron | ||
| 439 | |||
| 440 | login_as :aaron | ||
| 441 | put :revert, params: { :id => node.id, :return_to => node_path(node) } | ||
| 442 | assert_redirected_to node_path(node) | ||
| 443 | node.reload | ||
| 444 | assert node.draft.present? | ||
| 445 | assert node.autosave.blank? | ||
| 446 | end | ||
| 447 | |||
| 448 | test "reverting from nodes#edit without return_to still lands back in the editor when a draft remains" do | ||
| 449 | user = User.find_by_login("aaron") | ||
| 450 | node = Node.root.children.create!(:slug => "revert_default_test") | ||
| 451 | node.lock_for_editing!(user) | ||
| 452 | node.autosave!({:title => "v1"}, user) | ||
| 453 | node.save_draft!(user) | ||
| 454 | node.publish_draft! | ||
| 455 | node.lock_for_editing!(user) | ||
| 456 | node.autosave!({:title => "v2"}, user) | ||
| 457 | node.save_draft!(user) | ||
| 458 | node.lock_for_editing!(user) | ||
| 459 | node.autosave!({:title => "v3"}, user) | ||
| 460 | |||
| 461 | login_as :aaron | ||
| 462 | put :revert, params: { :id => node.id } | ||
| 463 | assert_redirected_to edit_node_path(node) | ||
| 464 | end | ||
| 426 | end | 465 | end |
