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/admin_controller_test.rb | 2 +- test/controllers/content_controller_test.rb | 14 ++++++------ test/controllers/nodes_controller_test.rb | 26 +++++++++++----------- test/controllers/revisions_controller_test.rb | 16 ++++++------- test/controllers/rss_controller_test.rb | 2 +- .../controllers/shared_previews_controller_test.rb | 2 +- test/controllers/tags_controller_test.rb | 2 +- 7 files changed, 32 insertions(+), 32 deletions(-) (limited to 'test/controllers') diff --git a/test/controllers/admin_controller_test.rb b/test/controllers/admin_controller_test.rb index 00a51e2..cba4a59 100644 --- a/test/controllers/admin_controller_test.rb +++ b/test/controllers/admin_controller_test.rb @@ -17,7 +17,7 @@ class AdminControllerTest < ActionController::TestCase test "dashboard_search returns matching tags and nodes grouped separately" do node = Node.root.children.create!(:slug => "dashboard_search_test") - node.find_or_create_draft(User.find_by_login("aaron")) + find_or_create_draft(node, User.find_by_login("aaron")) node.draft.update(:title => "Biometrics Workshop") node.draft.tag_list = "biometrics-workshop" node.draft.save! diff --git a/test/controllers/content_controller_test.rb b/test/controllers/content_controller_test.rb index 9313783..e8bc55f 100644 --- a/test/controllers/content_controller_test.rb +++ b/test/controllers/content_controller_test.rb @@ -39,7 +39,7 @@ class ContentControllerTest < ActionController::TestCase fill_pages_with_content new_node = create_node_under_root "fnord" - draft = new_node.find_or_create_draft @user1 + draft = find_or_create_draft(new_node, @user1) draft.body = '[aggregate tags="update" limit="20"]' draft.save new_node.publish_draft! @@ -58,7 +58,7 @@ class ContentControllerTest < ActionController::TestCase fill_pages_with_content new_node = create_node_under_root "fnord" - draft = new_node.find_or_create_draft @user1 + draft = find_or_create_draft(new_node, @user1) draft.body = '[aggregate tags="update" limit="20" partial="sidebar_title_only"]' draft.save new_node.publish_draft! @@ -72,7 +72,7 @@ class ContentControllerTest < ActionController::TestCase def test_nonexistant_custom_template_defaults_to_standard_template new_node = create_node_under_root "fnord" - draft = new_node.find_or_create_draft @user1 + draft = find_or_create_draft(new_node, @user1) draft.template_name = "huchibu" draft.save new_node.publish_draft! @@ -84,7 +84,7 @@ class ContentControllerTest < ActionController::TestCase def test_custom_template_no_date_and_author new_node = create_node_under_root "fnord" - draft = new_node.find_or_create_draft @user1 + draft = find_or_create_draft(new_node, @user1) draft.template_name = "no_date_and_author" draft.save new_node.publish_draft! @@ -96,7 +96,7 @@ class ContentControllerTest < ActionController::TestCase def test_aggregator_without_fill new_node = create_node_under_root "fnord" - draft = new_node.find_or_create_draft @user1 + draft = find_or_create_draft(new_node, @user1) draft.body = '' draft.save new_node.publish_draft! @@ -114,13 +114,13 @@ class ContentControllerTest < ActionController::TestCase end def fill_pages_with_content - d1 = @first_child.find_or_create_draft @user1 + d1 = find_or_create_draft(@first_child, @user1) d1.title = "one" d1.tag_list = "update" d1.save @first_child.publish_draft! - d2 = @second_child.find_or_create_draft @user1 + d2 = find_or_create_draft(@second_child, @user1) d2.title = "two" d2.tag_list = "update" d2.save 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! diff --git a/test/controllers/revisions_controller_test.rb b/test/controllers/revisions_controller_test.rb index e5726f7..96c6d6c 100644 --- a/test/controllers/revisions_controller_test.rb +++ b/test/controllers/revisions_controller_test.rb @@ -10,7 +10,7 @@ class RevisionsControllerTest < ActionController::TestCase draft = @node.draft draft.body = "first" @node.publish_draft! - @node.find_or_create_draft @user + find_or_create_draft(@node, @user) draft = @node.draft draft.update(:body => "second") @node.publish_draft! @@ -103,7 +103,7 @@ class RevisionsControllerTest < ActionController::TestCase test "diffing head against draft by name" do login_as :quentin - @node.find_or_create_draft(@user) + find_or_create_draft(@node, @user) @node.draft.update(:body => "draft body") post(:diff, params: { :node_id => @node.id, :start_revision => "head", :end_revision => "draft" }) @@ -119,7 +119,7 @@ class RevisionsControllerTest < ActionController::TestCase test "diffing by name shows a clear comparison label instead of a misleading revision picker" do login_as :quentin - @node.find_or_create_draft(@user) + find_or_create_draft(@node, @user) post(:diff, params: { :node_id => @node.id, :start_revision => "head", :end_revision => "draft" }) assert_response :success @@ -130,7 +130,7 @@ class RevisionsControllerTest < ActionController::TestCase test "pair-switcher buttons carry their params as real hidden fields, not a query string" do login_as :quentin - @node.find_or_create_draft(@user) + find_or_create_draft(@node, @user) @node.lock_for_editing!(@user) @node.autosave!({ :body => "unsaved" }, @user) @@ -142,7 +142,7 @@ class RevisionsControllerTest < ActionController::TestCase test "the view toggle is available even when comparing named layers" do login_as :quentin - @node.find_or_create_draft(@user) + find_or_create_draft(@node, @user) post(:diff, params: { :node_id => @node.id, :start_revision => "head", :end_revision => "draft" }) assert_response :success @@ -151,7 +151,7 @@ class RevisionsControllerTest < ActionController::TestCase test "diffing two revisions also shows tag, template, and asset changes" do login_as :quentin - @node.find_or_create_draft(@user) + find_or_create_draft(@node, @user) @node.draft.tag_list = "update" @node.draft.save! @@ -175,7 +175,7 @@ class RevisionsControllerTest < ActionController::TestCase node.draft.save! node.publish_draft! - node.find_or_create_draft(@user) + find_or_create_draft(node, @user) Globalize.with_locale(:en) { node.draft.update!(:title => "Changed in English only") } node.draft.save! @@ -191,7 +191,7 @@ class RevisionsControllerTest < ActionController::TestCase node.draft.save! node.publish_draft! - node.find_or_create_draft(@user) + find_or_create_draft(node, @user) Globalize.with_locale(:en) { node.draft.update!(:title => "English changed") } node.draft.save! diff --git a/test/controllers/rss_controller_test.rb b/test/controllers/rss_controller_test.rb index 7e28844..3f4b4fb 100644 --- a/test/controllers/rss_controller_test.rb +++ b/test/controllers/rss_controller_test.rb @@ -6,7 +6,7 @@ class RssControllerTest < ActionController::TestCase @user = User.create :login => 'rsstest', :email => 'rsstest@example.com', :password => 'foobar', :password_confirmation => 'foobar' @node = Node.root.children.create! :slug => 'rss_test_node' - draft = @node.find_or_create_draft @user + draft = find_or_create_draft(@node, @user) draft.title = "RSS Update Article" draft.tag_list = "update" draft.save diff --git a/test/controllers/shared_previews_controller_test.rb b/test/controllers/shared_previews_controller_test.rb index 5f2d20d..4ebc785 100644 --- a/test/controllers/shared_previews_controller_test.rb +++ b/test/controllers/shared_previews_controller_test.rb @@ -13,7 +13,7 @@ class SharedPreviewsControllerTest < ActionController::TestCase test "renders the preview for a brand-new draft on an already-published node" do node = Node.root.children.create!(:slug => "shared_preview_published_node_test") node.publish_draft! - node.find_or_create_draft(User.first) + find_or_create_draft(node, User.first) node.draft.ensure_preview_token! get :show, params: { :token => node.draft.preview_token } diff --git a/test/controllers/tags_controller_test.rb b/test/controllers/tags_controller_test.rb index 95c0d31..b2d30c5 100644 --- a/test/controllers/tags_controller_test.rb +++ b/test/controllers/tags_controller_test.rb @@ -6,7 +6,7 @@ class TagsControllerTest < ActionController::TestCase @user = User.create :login => 'tagtest', :email => 'tagtest@example.com', :password => 'foobar', :password_confirmation => 'foobar' @node = Node.root.children.create! :slug => 'tag_test_node' - draft = @node.find_or_create_draft @user + draft = find_or_create_draft(@node, @user) draft.title = "Tagged Article" draft.tag_list = "testtag" draft.save -- cgit v1.3