summaryrefslogtreecommitdiff
path: root/test/controllers
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-14 14:31:18 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-14 14:31:18 +0200
commitcca0e57b21d506cd341b927984bcb68f0e461783 (patch)
tree2d49cf1b678a3f5cf0fd20cd214b20524027ec50 /test/controllers
parent6b302d263ac66b521a743f1e8e1cc82997b54b5d (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')
-rw-r--r--test/controllers/admin_controller_test.rb2
-rw-r--r--test/controllers/content_controller_test.rb14
-rw-r--r--test/controllers/nodes_controller_test.rb26
-rw-r--r--test/controllers/revisions_controller_test.rb16
-rw-r--r--test/controllers/rss_controller_test.rb2
-rw-r--r--test/controllers/shared_previews_controller_test.rb2
-rw-r--r--test/controllers/tags_controller_test.rb2
7 files changed, 32 insertions, 32 deletions
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
17 17
18 test "dashboard_search returns matching tags and nodes grouped separately" do 18 test "dashboard_search returns matching tags and nodes grouped separately" do
19 node = Node.root.children.create!(:slug => "dashboard_search_test") 19 node = Node.root.children.create!(:slug => "dashboard_search_test")
20 node.find_or_create_draft(User.find_by_login("aaron")) 20 find_or_create_draft(node, User.find_by_login("aaron"))
21 node.draft.update(:title => "Biometrics Workshop") 21 node.draft.update(:title => "Biometrics Workshop")
22 node.draft.tag_list = "biometrics-workshop" 22 node.draft.tag_list = "biometrics-workshop"
23 node.draft.save! 23 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
39 fill_pages_with_content 39 fill_pages_with_content
40 40
41 new_node = create_node_under_root "fnord" 41 new_node = create_node_under_root "fnord"
42 draft = new_node.find_or_create_draft @user1 42 draft = find_or_create_draft(new_node, @user1)
43 draft.body = '[aggregate tags="update" limit="20"]' 43 draft.body = '[aggregate tags="update" limit="20"]'
44 draft.save 44 draft.save
45 new_node.publish_draft! 45 new_node.publish_draft!
@@ -58,7 +58,7 @@ class ContentControllerTest < ActionController::TestCase
58 fill_pages_with_content 58 fill_pages_with_content
59 59
60 new_node = create_node_under_root "fnord" 60 new_node = create_node_under_root "fnord"
61 draft = new_node.find_or_create_draft @user1 61 draft = find_or_create_draft(new_node, @user1)
62 draft.body = '[aggregate tags="update" limit="20" partial="sidebar_title_only"]' 62 draft.body = '[aggregate tags="update" limit="20" partial="sidebar_title_only"]'
63 draft.save 63 draft.save
64 new_node.publish_draft! 64 new_node.publish_draft!
@@ -72,7 +72,7 @@ class ContentControllerTest < ActionController::TestCase
72 72
73 def test_nonexistant_custom_template_defaults_to_standard_template 73 def test_nonexistant_custom_template_defaults_to_standard_template
74 new_node = create_node_under_root "fnord" 74 new_node = create_node_under_root "fnord"
75 draft = new_node.find_or_create_draft @user1 75 draft = find_or_create_draft(new_node, @user1)
76 draft.template_name = "huchibu" 76 draft.template_name = "huchibu"
77 draft.save 77 draft.save
78 new_node.publish_draft! 78 new_node.publish_draft!
@@ -84,7 +84,7 @@ class ContentControllerTest < ActionController::TestCase
84 84
85 def test_custom_template_no_date_and_author 85 def test_custom_template_no_date_and_author
86 new_node = create_node_under_root "fnord" 86 new_node = create_node_under_root "fnord"
87 draft = new_node.find_or_create_draft @user1 87 draft = find_or_create_draft(new_node, @user1)
88 draft.template_name = "no_date_and_author" 88 draft.template_name = "no_date_and_author"
89 draft.save 89 draft.save
90 new_node.publish_draft! 90 new_node.publish_draft!
@@ -96,7 +96,7 @@ class ContentControllerTest < ActionController::TestCase
96 96
97 def test_aggregator_without_fill 97 def test_aggregator_without_fill
98 new_node = create_node_under_root "fnord" 98 new_node = create_node_under_root "fnord"
99 draft = new_node.find_or_create_draft @user1 99 draft = find_or_create_draft(new_node, @user1)
100 draft.body = '<aggregate tags="xyzzy_unique_test_tag" limit="20" />' 100 draft.body = '<aggregate tags="xyzzy_unique_test_tag" limit="20" />'
101 draft.save 101 draft.save
102 new_node.publish_draft! 102 new_node.publish_draft!
@@ -114,13 +114,13 @@ class ContentControllerTest < ActionController::TestCase
114 end 114 end
115 115
116 def fill_pages_with_content 116 def fill_pages_with_content
117 d1 = @first_child.find_or_create_draft @user1 117 d1 = find_or_create_draft(@first_child, @user1)
118 d1.title = "one" 118 d1.title = "one"
119 d1.tag_list = "update" 119 d1.tag_list = "update"
120 d1.save 120 d1.save
121 @first_child.publish_draft! 121 @first_child.publish_draft!
122 122
123 d2 = @second_child.find_or_create_draft @user1 123 d2 = find_or_create_draft(@second_child, @user1)
124 d2.title = "two" 124 d2.title = "two"
125 d2.tag_list = "update" 125 d2.tag_list = "update"
126 d2.save 126 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
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!
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
10 draft = @node.draft 10 draft = @node.draft
11 draft.body = "first" 11 draft.body = "first"
12 @node.publish_draft! 12 @node.publish_draft!
13 @node.find_or_create_draft @user 13 find_or_create_draft(@node, @user)
14 draft = @node.draft 14 draft = @node.draft
15 draft.update(:body => "second") 15 draft.update(:body => "second")
16 @node.publish_draft! 16 @node.publish_draft!
@@ -103,7 +103,7 @@ class RevisionsControllerTest < ActionController::TestCase
103 103
104 test "diffing head against draft by name" do 104 test "diffing head against draft by name" do
105 login_as :quentin 105 login_as :quentin
106 @node.find_or_create_draft(@user) 106 find_or_create_draft(@node, @user)
107 @node.draft.update(:body => "draft body") 107 @node.draft.update(:body => "draft body")
108 108
109 post(:diff, params: { :node_id => @node.id, :start_revision => "head", :end_revision => "draft" }) 109 post(:diff, params: { :node_id => @node.id, :start_revision => "head", :end_revision => "draft" })
@@ -119,7 +119,7 @@ class RevisionsControllerTest < ActionController::TestCase
119 119
120 test "diffing by name shows a clear comparison label instead of a misleading revision picker" do 120 test "diffing by name shows a clear comparison label instead of a misleading revision picker" do
121 login_as :quentin 121 login_as :quentin
122 @node.find_or_create_draft(@user) 122 find_or_create_draft(@node, @user)
123 123
124 post(:diff, params: { :node_id => @node.id, :start_revision => "head", :end_revision => "draft" }) 124 post(:diff, params: { :node_id => @node.id, :start_revision => "head", :end_revision => "draft" })
125 assert_response :success 125 assert_response :success
@@ -130,7 +130,7 @@ class RevisionsControllerTest < ActionController::TestCase
130 130
131 test "pair-switcher buttons carry their params as real hidden fields, not a query string" do 131 test "pair-switcher buttons carry their params as real hidden fields, not a query string" do
132 login_as :quentin 132 login_as :quentin
133 @node.find_or_create_draft(@user) 133 find_or_create_draft(@node, @user)
134 @node.lock_for_editing!(@user) 134 @node.lock_for_editing!(@user)
135 @node.autosave!({ :body => "unsaved" }, @user) 135 @node.autosave!({ :body => "unsaved" }, @user)
136 136
@@ -142,7 +142,7 @@ class RevisionsControllerTest < ActionController::TestCase
142 142
143 test "the view toggle is available even when comparing named layers" do 143 test "the view toggle is available even when comparing named layers" do
144 login_as :quentin 144 login_as :quentin
145 @node.find_or_create_draft(@user) 145 find_or_create_draft(@node, @user)
146 146
147 post(:diff, params: { :node_id => @node.id, :start_revision => "head", :end_revision => "draft" }) 147 post(:diff, params: { :node_id => @node.id, :start_revision => "head", :end_revision => "draft" })
148 assert_response :success 148 assert_response :success
@@ -151,7 +151,7 @@ class RevisionsControllerTest < ActionController::TestCase
151 151
152 test "diffing two revisions also shows tag, template, and asset changes" do 152 test "diffing two revisions also shows tag, template, and asset changes" do
153 login_as :quentin 153 login_as :quentin
154 @node.find_or_create_draft(@user) 154 find_or_create_draft(@node, @user)
155 @node.draft.tag_list = "update" 155 @node.draft.tag_list = "update"
156 @node.draft.save! 156 @node.draft.save!
157 157
@@ -175,7 +175,7 @@ class RevisionsControllerTest < ActionController::TestCase
175 node.draft.save! 175 node.draft.save!
176 node.publish_draft! 176 node.publish_draft!
177 177
178 node.find_or_create_draft(@user) 178 find_or_create_draft(node, @user)
179 Globalize.with_locale(:en) { node.draft.update!(:title => "Changed in English only") } 179 Globalize.with_locale(:en) { node.draft.update!(:title => "Changed in English only") }
180 node.draft.save! 180 node.draft.save!
181 181
@@ -191,7 +191,7 @@ class RevisionsControllerTest < ActionController::TestCase
191 node.draft.save! 191 node.draft.save!
192 node.publish_draft! 192 node.publish_draft!
193 193
194 node.find_or_create_draft(@user) 194 find_or_create_draft(node, @user)
195 Globalize.with_locale(:en) { node.draft.update!(:title => "English changed") } 195 Globalize.with_locale(:en) { node.draft.update!(:title => "English changed") }
196 node.draft.save! 196 node.draft.save!
197 197
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
6 @user = User.create :login => 'rsstest', :email => 'rsstest@example.com', 6 @user = User.create :login => 'rsstest', :email => 'rsstest@example.com',
7 :password => 'foobar', :password_confirmation => 'foobar' 7 :password => 'foobar', :password_confirmation => 'foobar'
8 @node = Node.root.children.create! :slug => 'rss_test_node' 8 @node = Node.root.children.create! :slug => 'rss_test_node'
9 draft = @node.find_or_create_draft @user 9 draft = find_or_create_draft(@node, @user)
10 draft.title = "RSS Update Article" 10 draft.title = "RSS Update Article"
11 draft.tag_list = "update" 11 draft.tag_list = "update"
12 draft.save 12 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
13 test "renders the preview for a brand-new draft on an already-published node" do 13 test "renders the preview for a brand-new draft on an already-published node" do
14 node = Node.root.children.create!(:slug => "shared_preview_published_node_test") 14 node = Node.root.children.create!(:slug => "shared_preview_published_node_test")
15 node.publish_draft! 15 node.publish_draft!
16 node.find_or_create_draft(User.first) 16 find_or_create_draft(node, User.first)
17 node.draft.ensure_preview_token! 17 node.draft.ensure_preview_token!
18 18
19 get :show, params: { :token => node.draft.preview_token } 19 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
6 @user = User.create :login => 'tagtest', :email => 'tagtest@example.com', 6 @user = User.create :login => 'tagtest', :email => 'tagtest@example.com',
7 :password => 'foobar', :password_confirmation => 'foobar' 7 :password => 'foobar', :password_confirmation => 'foobar'
8 @node = Node.root.children.create! :slug => 'tag_test_node' 8 @node = Node.root.children.create! :slug => 'tag_test_node'
9 draft = @node.find_or_create_draft @user 9 draft = find_or_create_draft(@node, @user)
10 draft.title = "Tagged Article" 10 draft.title = "Tagged Article"
11 draft.tag_list = "testtag" 11 draft.tag_list = "testtag"
12 draft.save 12 draft.save