diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-14 14:31:18 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-14 14:31:18 +0200 |
| commit | cca0e57b21d506cd341b927984bcb68f0e461783 (patch) | |
| tree | 2d49cf1b678a3f5cf0fd20cd214b20524027ec50 /test/controllers/nodes_controller_test.rb | |
| parent | 6b302d263ac66b521a743f1e8e1cc82997b54b5d (diff) | |
Retire wipe_draft! and find_or_create_draft from production code
Both had already lost their reason to exist as production API:
wipe_draft!'s one remaining callsite (nodes#show) was removed two
sessions ago, and find_or_create_draft had zero production callers
left at all -- confirmed by a fresh grep, not assumed -- every one of
its ~65 call sites was test setup, unrelated to what those tests
actually cover.
wipe_draft! is deleted outright, along with its two tests -- the
lock/draft/autosave cleanup it silently performed already has
explicit, always-visible manual equivalents (Unlock, Discard
Autosave, Destroy Draft), so nothing real is lost.
find_or_create_draft moves to test_helper.rb as a plain method on
ActiveSupport::TestCase, alongside the create_node_with_draft/
create_node_with_published_page helpers already living there --
extending the framework's own designated test-extension point
rather than reopening the Node model from test code. Its three
tests of real dispatch behavior (idempotency on repeat calls, and
raising when a second user contends for the lock) are kept, since
~65 other tests depend on this helper actually working correctly;
only the call syntax changed, from node.find_or_create_draft(user)
to find_or_create_draft(node, user).
Diffstat (limited to 'test/controllers/nodes_controller_test.rb')
| -rw-r--r-- | test/controllers/nodes_controller_test.rb | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb index 81e3f45..9da9514 100644 --- a/test/controllers/nodes_controller_test.rb +++ b/test/controllers/nodes_controller_test.rb | |||
| @@ -89,7 +89,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 89 | 89 | ||
| 90 | assert_equal 1, node.pages.length | 90 | assert_equal 1, node.pages.length |
| 91 | 91 | ||
| 92 | draft = node.find_or_create_draft( User.first ) | 92 | draft = find_or_create_draft(node, User.first) |
| 93 | draft.title = "Hello" | 93 | draft.title = "Hello" |
| 94 | draft.body = "World" | 94 | draft.body = "World" |
| 95 | draft.save | 95 | draft.save |
| @@ -102,8 +102,8 @@ class NodesControllerTest < ActionController::TestCase | |||
| 102 | 102 | ||
| 103 | node.reload | 103 | node.reload |
| 104 | assert_equal 1, 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", find_or_create_draft(node, User.first).title |
| 106 | assert_equal "World", node.find_or_create_draft( User.first ).body | 106 | assert_equal "World", find_or_create_draft(node, User.first).body |
| 107 | end | 107 | end |
| 108 | 108 | ||
| 109 | test "editing a locked node raises LockedByAnotherUser Exception" do | 109 | test "editing a locked node raises LockedByAnotherUser Exception" do |
| @@ -228,7 +228,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 228 | test "unlocking a locked node" do | 228 | test "unlocking a locked node" do |
| 229 | login_as :quentin | 229 | login_as :quentin |
| 230 | node = create_node_with_published_page | 230 | node = create_node_with_published_page |
| 231 | node.find_or_create_draft User.first | 231 | find_or_create_draft(node, User.first) |
| 232 | 232 | ||
| 233 | assert node.locked? | 233 | assert node.locked? |
| 234 | 234 | ||
| @@ -250,7 +250,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 250 | Node.root.descendants.destroy_all | 250 | Node.root.descendants.destroy_all |
| 251 | login_as :quentin | 251 | login_as :quentin |
| 252 | node = create_node_with_published_page | 252 | node = create_node_with_published_page |
| 253 | node.find_or_create_draft User.first | 253 | find_or_create_draft(node, User.first) |
| 254 | 254 | ||
| 255 | other_node = Node.root.children.create( :slug => "other" ) | 255 | other_node = Node.root.children.create( :slug => "other" ) |
| 256 | 256 | ||
| @@ -274,7 +274,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 274 | Node.root.descendants.destroy_all | 274 | Node.root.descendants.destroy_all |
| 275 | node = create_node_with_published_page | 275 | node = create_node_with_published_page |
| 276 | assert_equal "quentin", node.head.user.login | 276 | assert_equal "quentin", node.head.user.login |
| 277 | node.find_or_create_draft users(:quentin) | 277 | find_or_create_draft(node, users(:quentin)) |
| 278 | assert node.draft.valid? | 278 | assert node.draft.valid? |
| 279 | assert node.valid? | 279 | assert node.valid? |
| 280 | 280 | ||
| @@ -336,7 +336,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 336 | 336 | ||
| 337 | test "unlocking and relocking changes editor if done by another user" do | 337 | test "unlocking and relocking changes editor if done by another user" do |
| 338 | node = create_node_with_published_page | 338 | node = create_node_with_published_page |
| 339 | draft = node.find_or_create_draft users(:quentin) | 339 | draft = find_or_create_draft(node, users(:quentin)) |
| 340 | assert_equal draft.user.login, draft.editor.login | 340 | assert_equal draft.user.login, draft.editor.login |
| 341 | assert node.locked? | 341 | assert node.locked? |
| 342 | node.unlock! | 342 | node.unlock! |
| @@ -481,13 +481,13 @@ class NodesControllerTest < ActionController::TestCase | |||
| 481 | 481 | ||
| 482 | test "chapters filters by kind, matching head or draft, and shows both by default" do | 482 | test "chapters filters by kind, matching head or draft, and shows both by default" do |
| 483 | erfa_node = Node.root.children.create!(:slug => "chapters_erfa_test") | 483 | erfa_node = Node.root.children.create!(:slug => "chapters_erfa_test") |
| 484 | erfa_node.find_or_create_draft(@user1) | 484 | find_or_create_draft(erfa_node, @user1) |
| 485 | erfa_node.draft.tag_list = "erfa-detail" | 485 | erfa_node.draft.tag_list = "erfa-detail" |
| 486 | erfa_node.draft.save! | 486 | erfa_node.draft.save! |
| 487 | erfa_node.publish_draft! | 487 | erfa_node.publish_draft! |
| 488 | 488 | ||
| 489 | chaostreff_node = Node.root.children.create!(:slug => "chapters_chaostreff_test") | 489 | chaostreff_node = Node.root.children.create!(:slug => "chapters_chaostreff_test") |
| 490 | chaostreff_node.find_or_create_draft(@user1) | 490 | find_or_create_draft(chaostreff_node, @user1) |
| 491 | chaostreff_node.draft.tag_list = "chaostreff-detail" | 491 | chaostreff_node.draft.tag_list = "chaostreff-detail" |
| 492 | chaostreff_node.draft.save! | 492 | chaostreff_node.draft.save! |
| 493 | chaostreff_node.publish_draft! | 493 | chaostreff_node.publish_draft! |
| @@ -549,13 +549,13 @@ class NodesControllerTest < ActionController::TestCase | |||
| 549 | 549 | ||
| 550 | test "tags path filters by an arbitrary raw tag, generalizing chapters" do | 550 | test "tags path filters by an arbitrary raw tag, generalizing chapters" do |
| 551 | presse_node = Node.root.children.create!(:slug => "tags_path_presse_test") | 551 | presse_node = Node.root.children.create!(:slug => "tags_path_presse_test") |
| 552 | presse_node.find_or_create_draft(@user1) | 552 | find_or_create_draft(presse_node, @user1) |
| 553 | presse_node.draft.tag_list = "pressemitteilung" | 553 | presse_node.draft.tag_list = "pressemitteilung" |
| 554 | presse_node.draft.save! | 554 | presse_node.draft.save! |
| 555 | presse_node.publish_draft! | 555 | presse_node.publish_draft! |
| 556 | 556 | ||
| 557 | erfa_node = Node.root.children.create!(:slug => "tags_path_erfa_test") | 557 | erfa_node = Node.root.children.create!(:slug => "tags_path_erfa_test") |
| 558 | erfa_node.find_or_create_draft(@user1) | 558 | find_or_create_draft(erfa_node, @user1) |
| 559 | erfa_node.draft.tag_list = "erfa-detail" | 559 | erfa_node.draft.tag_list = "erfa-detail" |
| 560 | erfa_node.draft.save! | 560 | erfa_node.draft.save! |
| 561 | erfa_node.publish_draft! | 561 | erfa_node.publish_draft! |
| @@ -572,13 +572,13 @@ class NodesControllerTest < ActionController::TestCase | |||
| 572 | 572 | ||
| 573 | test "tags path with multiple tags matches any of them, not all" do | 573 | test "tags path with multiple tags matches any of them, not all" do |
| 574 | erfa_node = Node.root.children.create!(:slug => "tags_path_multi_erfa_test") | 574 | erfa_node = Node.root.children.create!(:slug => "tags_path_multi_erfa_test") |
| 575 | erfa_node.find_or_create_draft(@user1) | 575 | find_or_create_draft(erfa_node, @user1) |
| 576 | erfa_node.draft.tag_list = "erfa-detail" | 576 | erfa_node.draft.tag_list = "erfa-detail" |
| 577 | erfa_node.draft.save! | 577 | erfa_node.draft.save! |
| 578 | erfa_node.publish_draft! | 578 | erfa_node.publish_draft! |
| 579 | 579 | ||
| 580 | chaostreff_node = Node.root.children.create!(:slug => "tags_path_multi_chaostreff_test") | 580 | chaostreff_node = Node.root.children.create!(:slug => "tags_path_multi_chaostreff_test") |
| 581 | chaostreff_node.find_or_create_draft(@user1) | 581 | find_or_create_draft(chaostreff_node, @user1) |
| 582 | chaostreff_node.draft.tag_list = "chaostreff-detail" | 582 | chaostreff_node.draft.tag_list = "chaostreff-detail" |
| 583 | chaostreff_node.draft.save! | 583 | chaostreff_node.draft.save! |
| 584 | chaostreff_node.publish_draft! | 584 | chaostreff_node.publish_draft! |
