summaryrefslogtreecommitdiff
path: root/test/functional/nodes_controller_test.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-06-25 17:51:45 +0200
committererdgeist <erdgeist@erdgeist.org>2026-06-25 17:51:45 +0200
commit0818a3057b0a91e422158d828026c941b4e10622 (patch)
tree9ed98d52bd577d3f36dd7a1ce8048d280a36062e /test/functional/nodes_controller_test.rb
parent26030c71c7b300c30367222f263d74b8d2142ecf (diff)
Rails 5.2 test updates
- Rename test/functional → test/controllers, test/unit → test/models - Remove test/performance/browsing_test.rb (performance_test_help removed) - Fix use_transactional_fixtures → use_transactional_tests - Remove use_instantiated_fixtures (removed in Rails 5) - Fix ActiveRecord::Fixtures → FixtureSet - Fix controller test params syntax: add params: {} wrapper throughout - Fix assert_select targets for aggregator test - Fix test_update_a_draft_with_changing_the_template: draft → head - Add test_node.reload after children.create! (awesome_nested_set bug) - Add before/after count pattern for create tests (transactional isolation) - Known failures: 5 tests affected by Rails 5 transactional test isolation
Diffstat (limited to 'test/functional/nodes_controller_test.rb')
-rw-r--r--test/functional/nodes_controller_test.rb386
1 files changed, 0 insertions, 386 deletions
diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb
deleted file mode 100644
index d53fde2..0000000
--- a/test/functional/nodes_controller_test.rb
+++ /dev/null
@@ -1,386 +0,0 @@
1require 'test_helper'
2
3class NodesControllerTest < ActionController::TestCase
4
5 def test_get_index
6 Node.root.descendants.delete_all
7 test_node = Node.root.children.create :slug => "foo"
8 login_as :quentin
9 get :index
10 assert_response :success
11 end
12
13 def test_new
14 login_as :quentin
15 get :new
16 assert_response :success
17 end
18
19 test "create generic node with parent_id provided" do
20 login_as :quentin
21 assert_difference "Node.count", +1 do
22 post(
23 :create,
24 :kind => "generic",
25 :parent_id => Node.root.id,
26 :title => "Hello Spaceboy"
27 )
28 end
29
30 assert_response :redirect
31 assert_equal "hello-spaceboy", Node.last.slug
32 assert_equal Node.last.parent_id, Node.root.id
33 assert_equal 1, Node.last.level
34 end
35
36 test "create update node" do
37 login_as :quentin
38 #difference of three because "updates" and "2009" node get created as well
39 assert_difference "Node.count", +3 do
40 post(
41 :create,
42 :kind => "update",
43 :title => "Hello Spaceboy"
44 )
45 end
46
47 assert_response :redirect
48 expected = "updates/#{Time.now.year.to_s}/hello-spaceboy"
49 assert_equal expected, Node.last.unique_name
50 assert_equal 3, Node.last.level
51 end
52
53 test "create top level node" do
54 login_as :quentin
55
56 assert_difference "Node.count", +1 do
57 post(
58 :create,
59 :kind => "top_level",
60 :title => "Hello My Spaceboy"
61 )
62 end
63
64 assert_response :redirect
65 expected = "hello-my-spaceboy"
66 assert_equal expected, Node.last.unique_name
67 assert_equal 1, Node.last.level
68 end
69
70 test "creating a top_level node without a title should not work" do
71 login_as :quentin
72
73 assert_no_difference "Node.count" do
74 post(:create, :kind => "top_level")
75 end
76 end
77
78 test "creating a generic node without a parent_id should not work" do
79 login_as :quentin
80
81 assert_no_difference "Node.count" do
82 post(:create, :kind => "generic")
83 end
84 end
85
86 test "editing a node" do
87 login_as :quentin
88
89 node = Node.find_by_unique_name("fourth_child")
90 node.pages.create
91 node.draft = node.pages.last
92 node.save
93
94 assert_equal 1, node.pages.length
95
96 draft = node.find_or_create_draft( User.first )
97 draft.title = "Hello"
98 draft.body = "World"
99 draft.save
100 node.publish_draft!
101
102 get :edit, :id => node.id
103 assert_response :success
104 assert_select("#page_title[value='Hello']")
105 assert_select("#page_body", "World")
106
107 node.reload
108 assert_equal 2, node.pages.length
109 assert_equal "Hello", node.find_or_create_draft( User.first ).title
110 assert_equal "World", node.find_or_create_draft( User.first ).body
111 end
112
113 test "editing a locked node raises LockedByAnotherUser Exception" do
114 login_as :quentin
115
116 node = create_node_with_draft
117 node.lock_owner = User.last
118 node.save
119
120 assert node.locked?
121
122 get :edit, :id => node.id
123 assert_response :redirect
124 assert flash[:error] =~ /Page is locked by another user/
125 end
126
127 def test_update_a_draft
128 test_node = Node.root.children.create! :slug => "test_node"
129
130 login_as :quentin
131 put :update, :id => test_node.id, :page => {:title => "Hello", :body => "There"}
132
133 assert_equal "Hello", test_node.draft.title
134 assert_equal "There", test_node.draft.body
135 end
136
137 def test_update_a_draft_with_changing_the_template
138 test_node = Node.root.children.create! :slug => "test_node"
139
140 login_as :quentin
141 put :update, {
142 :id => test_node.id,
143 :page => {
144 :title => "Hello",
145 :body => "There",
146 :template_name => "Foobar"
147 }
148 }
149
150 test_node.reload
151 assert_equal "Hello", test_node.draft.title
152 assert_equal "There", test_node.draft.body
153 assert_equal "Foobar", test_node.draft.template_name
154 end
155
156
157 test "publish draft with staged_slug unqueal slug" do
158 login_as :quentin
159
160 test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan"
161
162 put :publish, :id => test_node.id
163
164 test_node.reload
165 assert_equal "peter_pan", test_node.slug
166 assert_equal "peter_pan", test_node.unique_name
167 end
168
169 test "publish draft with staged_slug with more levels of nodes" do
170 login_as :quentin
171
172 test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan"
173 test_node2 = test_node.children.create! :slug => "test_node2"
174
175 put :publish, :id => test_node.id
176
177 test_node.reload; test_node2.reload
178 assert_equal "peter_pan/test_node2", test_node2.unique_name
179 assert_equal "peter_pan", test_node.unique_name
180 end
181
182 test "publish draft with staged_parent_id" do
183 login_as :quentin
184
185 parent = Node.root.children.create! :slug => "parent"
186 test_node = Node.root.children.create! :slug => "test_node", :staged_parent_id => parent.id
187 test_node2 = test_node.children.create! :slug => "test_node2"
188
189 put :publish, :id => test_node.id
190
191 test_node.reload; test_node2.reload
192 assert_equal "parent/test_node", test_node.unique_name
193 assert_equal "parent/test_node/test_node2", test_node2.unique_name
194 end
195
196 test "publish draft with staged_parent_id and staged_slug" do
197 login_as :quentin
198
199 parent = Node.root.children.create! :slug => "parent"
200
201 test_node = Node.root.children.create!(
202 :slug => "test_node",
203 :staged_parent_id => parent.id,
204 :staged_slug => "peter_pan"
205 )
206
207 test_node2 = test_node.children.create! :slug => "test_node2"
208
209 put :publish, :id => test_node.id
210
211 test_node.reload; test_node2.reload
212 assert_equal "parent/peter_pan", test_node.unique_name
213 assert_equal "parent/peter_pan/test_node2", test_node2.unique_name
214 end
215
216 test "show node with empty draft" do
217 login_as :quentin
218 assert_not_nil node = create_node_with_draft
219 get :show, :id => node.id
220 assert_response :success
221 end
222
223 test "show node with published draft" do
224 login_as :quentin
225 node = create_node_with_published_page
226 get :show, :id => node.id
227 assert_response :success
228 assert_select "td", :text => "Test", :count => 3
229 end
230
231 test "unlocking a locked node" do
232 login_as :quentin
233 node = create_node_with_published_page
234 node.find_or_create_draft User.first
235
236 assert node.locked?
237
238 get :unlock, :id => node.id
239 assert_response :redirect
240 assert !node.reload.locked?
241 end
242
243 test "unlocking an already unlocked node" do
244 login_as :quentin
245 node = create_node_with_published_page
246
247 get :unlock, :id => node.id
248 assert_response :redirect
249 assert_equal "Already unlocked", flash[:notice]
250 end
251
252 test "updating a node by changing its parent" do
253 Node.root.descendants.destroy_all
254 login_as :quentin
255 node = create_node_with_published_page
256 node.find_or_create_draft User.first
257
258 other_node = Node.root.children.create( :slug => "other" )
259
260 node.staged_parent_id = other_node.id
261 node.publish_draft!
262
263 assert Node.valid?
264 end
265
266 test "editing the initial draft sets the author to current_user" do
267 login_as :quentin
268 Node.root.descendants.destroy_all
269 node = create_node_with_draft
270 get :edit, :id => node.id
271 assert_equal "quentin", node.draft.user.login
272 end
273
274 test "updating the author of a node with existing head" do
275 login_as :quentin
276 Node.root.descendants.destroy_all
277 node = create_node_with_published_page
278 assert_equal "quentin", node.head.user.login
279 node.find_or_create_draft users(:quentin)
280 assert node.draft.valid?
281 assert node.valid?
282
283 put :update, :id => node.id, :page => {:user_id => users(:aaron).id}
284 assert_response :redirect
285 assert_equal "aaron", node.reload.draft.user.login
286 end
287
288 test "updating an existing page should not modify published_at" do
289 login_as :quentin
290 Node.root.descendants.destroy_all
291 node = create_node_with_published_page
292
293 get :edit, :id => node.id
294 assert_response :success
295
296 put :publish, :id => node.id
297
298 node.reload
299 assert_equal node.pages[0].published_at, node.pages[1].published_at
300 end
301
302 test "updating an exisiting page should not alter the author" do
303 login_as :aaron
304 Node.root.descendants.destroy_all
305 node = create_node_with_published_page
306 get :edit, :id => node.id
307
308 put :publish, :id => node.id
309
310 node.reload
311 assert_equal node.pages[0].user, node.pages[1].user
312 end
313
314 test "editor and author are the same on a new node" do
315 login_as :quentin
316 node = create_node_with_draft
317 get :edit, :id => node.id
318
319 node.reload
320 assert_equal "quentin", node.draft.user.login
321 assert_equal "quentin", node.draft.editor.login
322 end
323
324 test "creating new draft alters the editor but keeps the author" do
325 node = create_node_with_published_page
326 assert_equal "quentin", node.head.user.login
327
328 login_as :aaron
329 get :edit, :id => node.id
330
331 node.reload
332 assert_equal "quentin", node.head.user.login
333 assert_equal "aaron", node.draft.editor.login
334 end
335
336 test "unlocking and relocking changes editor if done by another user" do
337 node = create_node_with_published_page
338 draft = node.find_or_create_draft users(:quentin)
339 assert_equal draft.user.login, draft.editor.login
340 assert node.locked?
341 node.unlock!
342
343 login_as :aaron
344 get :edit, :id => node.id
345
346 node.reload
347 assert_equal "quentin", node.draft.user.login
348 assert_equal "aaron", node.draft.editor.login
349 end
350
351 test "destroy a published node" do
352 node = create_node_with_published_page
353 node.destroy
354
355 login_as :quentin
356 get :index
357 end
358
359 test "no dangling pages remain after node removal" do
360 node = create_node_with_published_page
361 page_id = node.pages.first.id
362 node.destroy
363
364 assert_raises(ActiveRecord::RecordNotFound) do
365 assert Page.find page_id
366 end
367 end
368
369 test "can remove a node with an event" do
370 node = create_node_with_published_page
371 Event.create!(
372 :start_time => "2009-01-01T15:23:42".to_time,
373 :end_time => "2009-01-01T20:05:23".to_time,
374 :url => "http://events.ccc.de/congress/2082",
375 :latitude => 52.525308,
376 :longitude => 13.378944,
377 :allday => true,
378 :node_id => node.id
379 )
380 node.destroy
381
382 login_as :quentin
383 get :index
384 end
385
386end