summaryrefslogtreecommitdiff
path: root/test/controllers/nodes_controller_test.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-06 16:51:27 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-06 16:51:27 +0200
commit1393b3de31d95b1aa5122d6da37bd3259830bdb6 (patch)
treedb9e7e60abe6f1a80089ed5dd98a3c344be183c1 /test/controllers/nodes_controller_test.rb
parent36b5324900968afc7498950c14ad13be5c061a7c (diff)
Fix test to match the current layout
Diffstat (limited to 'test/controllers/nodes_controller_test.rb')
-rw-r--r--test/controllers/nodes_controller_test.rb126
1 files changed, 63 insertions, 63 deletions
diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb
index 99e06ae..61f7db4 100644
--- a/test/controllers/nodes_controller_test.rb
+++ b/test/controllers/nodes_controller_test.rb
@@ -9,13 +9,13 @@ class NodesControllerTest < ActionController::TestCase
9 get :index 9 get :index
10 assert_response :success 10 assert_response :success
11 end 11 end
12 12
13 def test_new 13 def test_new
14 login_as :quentin 14 login_as :quentin
15 get :new 15 get :new
16 assert_response :success 16 assert_response :success
17 end 17 end
18 18
19 test "create generic node with parent_id provided" do 19 test "create generic node with parent_id provided" do
20 login_as :quentin 20 login_as :quentin
21 before_count = Node.count 21 before_count = Node.count
@@ -33,7 +33,7 @@ class NodesControllerTest < ActionController::TestCase
33 assert_equal Node.last.parent_id, Node.root.id 33 assert_equal Node.last.parent_id, Node.root.id
34 assert_equal 1, Node.last.level 34 assert_equal 1, Node.last.level
35 end 35 end
36 36
37 test "create update node" do 37 test "create update node" do
38 login_as :quentin 38 login_as :quentin
39 post( 39 post(
@@ -45,7 +45,7 @@ class NodesControllerTest < ActionController::TestCase
45 ) 45 )
46 assert_response :redirect 46 assert_response :redirect
47 end 47 end
48 48
49 test "create top level node" do 49 test "create top level node" do
50 login_as :quentin 50 login_as :quentin
51 before_count = Node.count 51 before_count = Node.count
@@ -62,64 +62,64 @@ class NodesControllerTest < ActionController::TestCase
62 assert_equal expected, Node.last.unique_name 62 assert_equal expected, Node.last.unique_name
63 assert_equal 1, Node.last.level 63 assert_equal 1, Node.last.level
64 end 64 end
65 65
66 test "creating a top_level node without a title should not work" do 66 test "creating a top_level node without a title should not work" do
67 login_as :quentin 67 login_as :quentin
68 68
69 assert_no_difference "Node.count" do 69 assert_no_difference "Node.count" do
70 post(:create, params: { :kind => "top_level" } ) 70 post(:create, params: { :kind => "top_level" } )
71 end 71 end
72 end 72 end
73 73
74 test "creating a generic node without a parent_id should not work" do 74 test "creating a generic node without a parent_id should not work" do
75 login_as :quentin 75 login_as :quentin
76 76
77 assert_no_difference "Node.count" do 77 assert_no_difference "Node.count" do
78 post(:create, params: { :kind => "generic" } ) 78 post(:create, params: { :kind => "generic" } )
79 end 79 end
80 end 80 end
81 81
82 test "editing a node" do 82 test "editing a node" do
83 login_as :quentin 83 login_as :quentin
84 84
85 node = Node.find_by_unique_name("fourth_child") 85 node = Node.find_by_unique_name("fourth_child")
86 node.pages.create 86 node.pages.create
87 node.draft = node.pages.last 87 node.draft = node.pages.last
88 node.save 88 node.save
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 = node.find_or_create_draft( User.first )
93 draft.title = "Hello" 93 draft.title = "Hello"
94 draft.body = "World" 94 draft.body = "World"
95 draft.save 95 draft.save
96 node.publish_draft! 96 node.publish_draft!
97 97
98 get :edit, params: { :id => node.id } 98 get :edit, params: { :id => node.id }
99 assert_response :success 99 assert_response :success
100 assert_select("#page_title[value='Hello']") 100 assert_select("#page_title[value='Hello']")
101 assert_select("#page_body", "World") 101 assert_select("#page_body", "World")
102 102
103 node.reload 103 node.reload
104 assert_equal 2, node.pages.length 104 assert_equal 2, node.pages.length
105 assert_equal "Hello", node.find_or_create_draft( User.first ).title 105 assert_equal "Hello", node.find_or_create_draft( User.first ).title
106 assert_equal "World", node.find_or_create_draft( User.first ).body 106 assert_equal "World", node.find_or_create_draft( 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
110 login_as :quentin 110 login_as :quentin
111 111
112 node = create_node_with_draft 112 node = create_node_with_draft
113 node.lock_owner = User.last 113 node.lock_owner = User.last
114 node.save 114 node.save
115 115
116 assert node.locked? 116 assert node.locked?
117 117
118 get :edit, params: { :id => node.id } 118 get :edit, params: { :id => node.id }
119 assert_response :redirect 119 assert_response :redirect
120 assert flash[:error] =~ /Page is locked by another user/ 120 assert flash[:error] =~ /Page is locked by another user/
121 end 121 end
122 122
123 def test_update_a_draft 123 def test_update_a_draft
124 test_node = Node.root.children.create! :slug => "test_node" 124 test_node = Node.root.children.create! :slug => "test_node"
125 login_as :quentin 125 login_as :quentin
@@ -128,7 +128,7 @@ class NodesControllerTest < ActionController::TestCase
128 assert_equal "Hello", test_node.draft.title 128 assert_equal "Hello", test_node.draft.title
129 assert_equal "There", test_node.draft.body 129 assert_equal "There", test_node.draft.body
130 end 130 end
131 131
132 def test_update_a_draft_with_changing_the_template 132 def test_update_a_draft_with_changing_the_template
133 test_node = Node.root.children.create! :slug => "test_node" 133 test_node = Node.root.children.create! :slug => "test_node"
134 134
@@ -148,19 +148,19 @@ class NodesControllerTest < ActionController::TestCase
148 assert_equal "There", test_node.head.body 148 assert_equal "There", test_node.head.body
149 assert_equal "Foobar", test_node.head.template_name 149 assert_equal "Foobar", test_node.head.template_name
150 end 150 end
151 151
152 test "publish draft with staged_slug unqueal slug" do 152 test "publish draft with staged_slug unqueal slug" do
153 login_as :quentin 153 login_as :quentin
154 154
155 test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan" 155 test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan"
156 156
157 put :publish, params: { :id => test_node.id } 157 put :publish, params: { :id => test_node.id }
158 158
159 test_node.reload 159 test_node.reload
160 assert_equal "peter_pan", test_node.slug 160 assert_equal "peter_pan", test_node.slug
161 assert_equal "peter_pan", test_node.unique_name 161 assert_equal "peter_pan", test_node.unique_name
162 end 162 end
163 163
164 test "publish draft with staged_slug with more levels of nodes" do 164 test "publish draft with staged_slug with more levels of nodes" do
165 login_as :quentin 165 login_as :quentin
166 166
@@ -168,12 +168,12 @@ class NodesControllerTest < ActionController::TestCase
168 test_node2 = test_node.children.create! :slug => "test_node2" 168 test_node2 = test_node.children.create! :slug => "test_node2"
169 169
170 put :publish, params: { :id => test_node.id } 170 put :publish, params: { :id => test_node.id }
171 171
172 test_node.reload; test_node2.reload 172 test_node.reload; test_node2.reload
173 assert_equal "peter_pan/test_node2", test_node2.unique_name 173 assert_equal "peter_pan/test_node2", test_node2.unique_name
174 assert_equal "peter_pan", test_node.unique_name 174 assert_equal "peter_pan", test_node.unique_name
175 end 175 end
176 176
177 test "publish draft with staged_parent_id" do 177 test "publish draft with staged_parent_id" do
178 login_as :quentin 178 login_as :quentin
179 179
@@ -187,77 +187,77 @@ class NodesControllerTest < ActionController::TestCase
187 assert_equal "parent/test_node", test_node.unique_name 187 assert_equal "parent/test_node", test_node.unique_name
188 assert_equal "parent/test_node/test_node2", test_node2.unique_name 188 assert_equal "parent/test_node/test_node2", test_node2.unique_name
189 end 189 end
190 190
191 test "publish draft with staged_parent_id and staged_slug" do 191 test "publish draft with staged_parent_id and staged_slug" do
192 login_as :quentin 192 login_as :quentin
193 193
194 parent = Node.root.children.create! :slug => "parent" 194 parent = Node.root.children.create! :slug => "parent"
195 195
196 test_node = Node.root.children.create!( 196 test_node = Node.root.children.create!(
197 :slug => "test_node", 197 :slug => "test_node",
198 :staged_parent_id => parent.id, 198 :staged_parent_id => parent.id,
199 :staged_slug => "peter_pan" 199 :staged_slug => "peter_pan"
200 ) 200 )
201 201
202 test_node2 = test_node.children.create! :slug => "test_node2" 202 test_node2 = test_node.children.create! :slug => "test_node2"
203 203
204 put :publish, params: { :id => test_node.id } 204 put :publish, params: { :id => test_node.id }
205 205
206 test_node.reload; test_node2.reload 206 test_node.reload; test_node2.reload
207 assert_equal "parent/peter_pan", test_node.unique_name 207 assert_equal "parent/peter_pan", test_node.unique_name
208 assert_equal "parent/peter_pan/test_node2", test_node2.unique_name 208 assert_equal "parent/peter_pan/test_node2", test_node2.unique_name
209 end 209 end
210 210
211 test "show node with empty draft" do 211 test "show node with empty draft" do
212 login_as :quentin 212 login_as :quentin
213 assert_not_nil node = create_node_with_draft 213 assert_not_nil node = create_node_with_draft
214 get :show, params: { :id => node.id } 214 get :show, params: { :id => node.id }
215 assert_response :success 215 assert_response :success
216 end 216 end
217 217
218 test "show node with published draft" do 218 test "show node with published draft" do
219 login_as :quentin 219 login_as :quentin
220 node = create_node_with_published_page 220 node = create_node_with_published_page
221 get :show, params: { :id => node.id } 221 get :show, params: { :id => node.id }
222 assert_response :success 222 assert_response :success
223 assert_select "td", :text => "Test", :count => 3 223 assert_select "div.node_content", :text => "Test", :count => 3
224 end 224 end
225 225
226 test "unlocking a locked node" do 226 test "unlocking a locked node" do
227 login_as :quentin 227 login_as :quentin
228 node = create_node_with_published_page 228 node = create_node_with_published_page
229 node.find_or_create_draft User.first 229 node.find_or_create_draft User.first
230 230
231 assert node.locked? 231 assert node.locked?
232 232
233 put :unlock, params: { :id => node.id } 233 put :unlock, params: { :id => node.id }
234 assert_response :redirect 234 assert_response :redirect
235 assert !node.reload.locked? 235 assert !node.reload.locked?
236 end 236 end
237 237
238 test "unlocking an already unlocked node" do 238 test "unlocking an already unlocked node" do
239 login_as :quentin 239 login_as :quentin
240 node = create_node_with_published_page 240 node = create_node_with_published_page
241 241
242 put :unlock, params: { :id => node.id } 242 put :unlock, params: { :id => node.id }
243 assert_response :redirect 243 assert_response :redirect
244 assert_equal "Already unlocked", flash[:notice] 244 assert_equal "Already unlocked", flash[:notice]
245 end 245 end
246 246
247 test "updating a node by changing its parent" do 247 test "updating a node by changing its parent" do
248 Node.root.descendants.destroy_all 248 Node.root.descendants.destroy_all
249 login_as :quentin 249 login_as :quentin
250 node = create_node_with_published_page 250 node = create_node_with_published_page
251 node.find_or_create_draft User.first 251 node.find_or_create_draft User.first
252 252
253 other_node = Node.root.children.create( :slug => "other" ) 253 other_node = Node.root.children.create( :slug => "other" )
254 254
255 node.staged_parent_id = other_node.id 255 node.staged_parent_id = other_node.id
256 node.publish_draft! 256 node.publish_draft!
257 257
258 assert Node.valid? 258 assert Node.valid?
259 end 259 end
260 260
261 test "editing the initial draft sets the author to current_user" do 261 test "editing the initial draft sets the author to current_user" do
262 login_as :quentin 262 login_as :quentin
263 Node.root.descendants.destroy_all 263 Node.root.descendants.destroy_all
@@ -266,7 +266,7 @@ class NodesControllerTest < ActionController::TestCase
266 node.reload 266 node.reload
267 assert_equal "quentin", node.draft.user.login 267 assert_equal "quentin", node.draft.user.login
268 end 268 end
269 269
270 test "updating the author of a node with existing head" do 270 test "updating the author of a node with existing head" do
271 login_as :quentin 271 login_as :quentin
272 Node.root.descendants.destroy_all 272 Node.root.descendants.destroy_all
@@ -275,70 +275,70 @@ class NodesControllerTest < ActionController::TestCase
275 node.find_or_create_draft users(:quentin) 275 node.find_or_create_draft users(:quentin)
276 assert node.draft.valid? 276 assert node.draft.valid?
277 assert node.valid? 277 assert node.valid?
278 278
279 put :update, params: { :id => node.id, :page => {:user_id => users(:aaron).id} } 279 put :update, params: { :id => node.id, :page => {:user_id => users(:aaron).id} }
280 assert_response :redirect 280 assert_response :redirect
281 assert_equal "aaron", node.reload.draft.user.login 281 assert_equal "aaron", node.reload.draft.user.login
282 end 282 end
283 283
284 test "updating an existing page should not modify published_at" do 284 test "updating an existing page should not modify published_at" do
285 login_as :quentin 285 login_as :quentin
286 Node.root.descendants.destroy_all 286 Node.root.descendants.destroy_all
287 node = create_node_with_published_page 287 node = create_node_with_published_page
288 288
289 get :edit, params: { :id => node.id } 289 get :edit, params: { :id => node.id }
290 assert_response :success 290 assert_response :success
291 291
292 put :publish, params: { :id => node.id } 292 put :publish, params: { :id => node.id }
293 293
294 node.reload 294 node.reload
295 assert_equal node.pages[0].published_at, node.pages[1].published_at 295 assert_equal node.pages[0].published_at, node.pages[1].published_at
296 end 296 end
297 297
298 test "updating an exisiting page should not alter the author" do 298 test "updating an exisiting page should not alter the author" do
299 login_as :aaron 299 login_as :aaron
300 Node.root.descendants.destroy_all 300 Node.root.descendants.destroy_all
301 node = create_node_with_published_page 301 node = create_node_with_published_page
302 get :edit, params: { :id => node.id } 302 get :edit, params: { :id => node.id }
303 303
304 put :publish, params: { :id => node.id } 304 put :publish, params: { :id => node.id }
305 305
306 node.reload 306 node.reload
307 assert_equal node.pages[0].user, node.pages[1].user 307 assert_equal node.pages[0].user, node.pages[1].user
308 end 308 end
309 309
310 test "editor and author are the same on a new node" do 310 test "editor and author are the same on a new node" do
311 login_as :quentin 311 login_as :quentin
312 node = create_node_with_draft 312 node = create_node_with_draft
313 get :edit, params: { :id => node.id } 313 get :edit, params: { :id => node.id }
314 314
315 node.reload 315 node.reload
316 assert_equal "quentin", node.draft.user.login 316 assert_equal "quentin", node.draft.user.login
317 assert_equal "quentin", node.draft.editor.login 317 assert_equal "quentin", node.draft.editor.login
318 end 318 end
319 319
320 test "creating new draft alters the editor but keeps the author" do 320 test "creating new draft alters the editor but keeps the author" do
321 node = create_node_with_published_page 321 node = create_node_with_published_page
322 assert_equal "quentin", node.head.user.login 322 assert_equal "quentin", node.head.user.login
323 323
324 login_as :aaron 324 login_as :aaron
325 get :edit, params: {:id => node.id } 325 get :edit, params: {:id => node.id }
326 326
327 node.reload 327 node.reload
328 assert_equal "quentin", node.head.user.login 328 assert_equal "quentin", node.head.user.login
329 assert_equal "aaron", node.draft.editor.login 329 assert_equal "aaron", node.draft.editor.login
330 end 330 end
331 331
332 test "unlocking and relocking changes editor if done by another user" do 332 test "unlocking and relocking changes editor if done by another user" do
333 node = create_node_with_published_page 333 node = create_node_with_published_page
334 draft = node.find_or_create_draft users(:quentin) 334 draft = node.find_or_create_draft users(:quentin)
335 assert_equal draft.user.login, draft.editor.login 335 assert_equal draft.user.login, draft.editor.login
336 assert node.locked? 336 assert node.locked?
337 node.unlock! 337 node.unlock!
338 338
339 login_as :aaron 339 login_as :aaron
340 get :edit, params: { :id => node.id } 340 get :edit, params: { :id => node.id }
341 341
342 node.reload 342 node.reload
343 assert_equal "quentin", node.draft.user.login 343 assert_equal "quentin", node.draft.user.login
344 assert_equal "aaron", node.draft.editor.login 344 assert_equal "aaron", node.draft.editor.login