From cca0e57b21d506cd341b927984bcb68f0e461783 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Tue, 14 Jul 2026 14:31:18 +0200 Subject: 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). --- test/controllers/nodes_controller_test.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'test/controllers/nodes_controller_test.rb') 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 assert_equal 1, node.pages.length - draft = node.find_or_create_draft( User.first ) + draft = find_or_create_draft(node, User.first) draft.title = "Hello" draft.body = "World" draft.save @@ -102,8 +102,8 @@ class NodesControllerTest < ActionController::TestCase node.reload assert_equal 1, node.pages.length - assert_equal "Hello", node.find_or_create_draft( User.first ).title - assert_equal "World", node.find_or_create_draft( User.first ).body + assert_equal "Hello", find_or_create_draft(node, User.first).title + assert_equal "World", find_or_create_draft(node, User.first).body end test "editing a locked node raises LockedByAnotherUser Exception" do @@ -228,7 +228,7 @@ class NodesControllerTest < ActionController::TestCase test "unlocking a locked node" do login_as :quentin node = create_node_with_published_page - node.find_or_create_draft User.first + find_or_create_draft(node, User.first) assert node.locked? @@ -250,7 +250,7 @@ class NodesControllerTest < ActionController::TestCase Node.root.descendants.destroy_all login_as :quentin node = create_node_with_published_page - node.find_or_create_draft User.first + find_or_create_draft(node, User.first) other_node = Node.root.children.create( :slug => "other" ) @@ -274,7 +274,7 @@ class NodesControllerTest < ActionController::TestCase Node.root.descendants.destroy_all node = create_node_with_published_page assert_equal "quentin", node.head.user.login - node.find_or_create_draft users(:quentin) + find_or_create_draft(node, users(:quentin)) assert node.draft.valid? assert node.valid? @@ -336,7 +336,7 @@ class NodesControllerTest < ActionController::TestCase test "unlocking and relocking changes editor if done by another user" do node = create_node_with_published_page - draft = node.find_or_create_draft users(:quentin) + draft = find_or_create_draft(node, users(:quentin)) assert_equal draft.user.login, draft.editor.login assert node.locked? node.unlock! @@ -481,13 +481,13 @@ class NodesControllerTest < ActionController::TestCase test "chapters filters by kind, matching head or draft, and shows both by default" do erfa_node = Node.root.children.create!(:slug => "chapters_erfa_test") - erfa_node.find_or_create_draft(@user1) + find_or_create_draft(erfa_node, @user1) erfa_node.draft.tag_list = "erfa-detail" erfa_node.draft.save! erfa_node.publish_draft! chaostreff_node = Node.root.children.create!(:slug => "chapters_chaostreff_test") - chaostreff_node.find_or_create_draft(@user1) + find_or_create_draft(chaostreff_node, @user1) chaostreff_node.draft.tag_list = "chaostreff-detail" chaostreff_node.draft.save! chaostreff_node.publish_draft! @@ -549,13 +549,13 @@ class NodesControllerTest < ActionController::TestCase test "tags path filters by an arbitrary raw tag, generalizing chapters" do presse_node = Node.root.children.create!(:slug => "tags_path_presse_test") - presse_node.find_or_create_draft(@user1) + find_or_create_draft(presse_node, @user1) presse_node.draft.tag_list = "pressemitteilung" presse_node.draft.save! presse_node.publish_draft! erfa_node = Node.root.children.create!(:slug => "tags_path_erfa_test") - erfa_node.find_or_create_draft(@user1) + find_or_create_draft(erfa_node, @user1) erfa_node.draft.tag_list = "erfa-detail" erfa_node.draft.save! erfa_node.publish_draft! @@ -572,13 +572,13 @@ class NodesControllerTest < ActionController::TestCase test "tags path with multiple tags matches any of them, not all" do erfa_node = Node.root.children.create!(:slug => "tags_path_multi_erfa_test") - erfa_node.find_or_create_draft(@user1) + find_or_create_draft(erfa_node, @user1) erfa_node.draft.tag_list = "erfa-detail" erfa_node.draft.save! erfa_node.publish_draft! chaostreff_node = Node.root.children.create!(:slug => "tags_path_multi_chaostreff_test") - chaostreff_node.find_or_create_draft(@user1) + find_or_create_draft(chaostreff_node, @user1) chaostreff_node.draft.tag_list = "chaostreff-detail" chaostreff_node.draft.save! chaostreff_node.publish_draft! -- cgit v1.3