diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 23:33:11 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 23:33:11 +0200 |
| commit | 8eab68f2c5a3c126e2fec2ecdfa7ace87ce0937b (patch) | |
| tree | f446ebc26a7707c7b64a937aa51a155df146c80a /test/controllers/nodes_controller_test.rb | |
| parent | 42714c697273a7117c6b355fab26c8c35e336ad1 (diff) | |
| parent | cdf5d9941ca866d437612d2f863eac6eb0b3db12 (diff) | |
Merge branch 'erdgeist-revive-events'
Diffstat (limited to 'test/controllers/nodes_controller_test.rb')
| -rw-r--r-- | test/controllers/nodes_controller_test.rb | 400 |
1 files changed, 334 insertions, 66 deletions
diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb index 53799f1..81e3f45 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,77 +62,79 @@ 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 1, 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 |
| 126 | get :edit, params: { :id => test_node.id } | ||
| 126 | put :update, params: { :id => test_node.id, :page => {:title => "Hello", :body => "There"} } | 127 | put :update, params: { :id => test_node.id, :page => {:title => "Hello", :body => "There"} } |
| 127 | test_node.reload | 128 | test_node.reload |
| 128 | assert_equal "Hello", test_node.draft.title | 129 | assert_equal "Hello", test_node.draft.title |
| 129 | assert_equal "There", test_node.draft.body | 130 | assert_equal "There", test_node.draft.body |
| 130 | end | 131 | end |
| 131 | 132 | ||
| 132 | def test_update_a_draft_with_changing_the_template | 133 | def test_update_a_draft_with_changing_the_template |
| 133 | test_node = Node.root.children.create! :slug => "test_node" | 134 | test_node = Node.root.children.create! :slug => "test_node" |
| 134 | 135 | ||
| 135 | login_as :quentin | 136 | login_as :quentin |
| 137 | get :edit, params: { :id => test_node.id } | ||
| 136 | put :update, params: { | 138 | put :update, params: { |
| 137 | :id => test_node.id, | 139 | :id => test_node.id, |
| 138 | :page => { | 140 | :page => { |
| @@ -148,19 +150,19 @@ class NodesControllerTest < ActionController::TestCase | |||
| 148 | assert_equal "There", test_node.head.body | 150 | assert_equal "There", test_node.head.body |
| 149 | assert_equal "Foobar", test_node.head.template_name | 151 | assert_equal "Foobar", test_node.head.template_name |
| 150 | end | 152 | end |
| 151 | 153 | ||
| 152 | test "publish draft with staged_slug unqueal slug" do | 154 | test "publish draft with staged_slug unqueal slug" do |
| 153 | login_as :quentin | 155 | login_as :quentin |
| 154 | 156 | ||
| 155 | test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan" | 157 | test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan" |
| 156 | 158 | ||
| 157 | put :publish, params: { :id => test_node.id } | 159 | put :publish, params: { :id => test_node.id } |
| 158 | 160 | ||
| 159 | test_node.reload | 161 | test_node.reload |
| 160 | assert_equal "peter_pan", test_node.slug | 162 | assert_equal "peter_pan", test_node.slug |
| 161 | assert_equal "peter_pan", test_node.unique_name | 163 | assert_equal "peter_pan", test_node.unique_name |
| 162 | end | 164 | end |
| 163 | 165 | ||
| 164 | test "publish draft with staged_slug with more levels of nodes" do | 166 | test "publish draft with staged_slug with more levels of nodes" do |
| 165 | login_as :quentin | 167 | login_as :quentin |
| 166 | 168 | ||
| @@ -168,12 +170,12 @@ class NodesControllerTest < ActionController::TestCase | |||
| 168 | test_node2 = test_node.children.create! :slug => "test_node2" | 170 | test_node2 = test_node.children.create! :slug => "test_node2" |
| 169 | 171 | ||
| 170 | put :publish, params: { :id => test_node.id } | 172 | put :publish, params: { :id => test_node.id } |
| 171 | 173 | ||
| 172 | test_node.reload; test_node2.reload | 174 | test_node.reload; test_node2.reload |
| 173 | assert_equal "peter_pan/test_node2", test_node2.unique_name | 175 | assert_equal "peter_pan/test_node2", test_node2.unique_name |
| 174 | assert_equal "peter_pan", test_node.unique_name | 176 | assert_equal "peter_pan", test_node.unique_name |
| 175 | end | 177 | end |
| 176 | 178 | ||
| 177 | test "publish draft with staged_parent_id" do | 179 | test "publish draft with staged_parent_id" do |
| 178 | login_as :quentin | 180 | login_as :quentin |
| 179 | 181 | ||
| @@ -187,77 +189,77 @@ class NodesControllerTest < ActionController::TestCase | |||
| 187 | assert_equal "parent/test_node", test_node.unique_name | 189 | assert_equal "parent/test_node", test_node.unique_name |
| 188 | assert_equal "parent/test_node/test_node2", test_node2.unique_name | 190 | assert_equal "parent/test_node/test_node2", test_node2.unique_name |
| 189 | end | 191 | end |
| 190 | 192 | ||
| 191 | test "publish draft with staged_parent_id and staged_slug" do | 193 | test "publish draft with staged_parent_id and staged_slug" do |
| 192 | login_as :quentin | 194 | login_as :quentin |
| 193 | 195 | ||
| 194 | parent = Node.root.children.create! :slug => "parent" | 196 | parent = Node.root.children.create! :slug => "parent" |
| 195 | 197 | ||
| 196 | test_node = Node.root.children.create!( | 198 | test_node = Node.root.children.create!( |
| 197 | :slug => "test_node", | 199 | :slug => "test_node", |
| 198 | :staged_parent_id => parent.id, | 200 | :staged_parent_id => parent.id, |
| 199 | :staged_slug => "peter_pan" | 201 | :staged_slug => "peter_pan" |
| 200 | ) | 202 | ) |
| 201 | 203 | ||
| 202 | test_node2 = test_node.children.create! :slug => "test_node2" | 204 | test_node2 = test_node.children.create! :slug => "test_node2" |
| 203 | 205 | ||
| 204 | put :publish, params: { :id => test_node.id } | 206 | put :publish, params: { :id => test_node.id } |
| 205 | 207 | ||
| 206 | test_node.reload; test_node2.reload | 208 | test_node.reload; test_node2.reload |
| 207 | assert_equal "parent/peter_pan", test_node.unique_name | 209 | assert_equal "parent/peter_pan", test_node.unique_name |
| 208 | assert_equal "parent/peter_pan/test_node2", test_node2.unique_name | 210 | assert_equal "parent/peter_pan/test_node2", test_node2.unique_name |
| 209 | end | 211 | end |
| 210 | 212 | ||
| 211 | test "show node with empty draft" do | 213 | test "show node with empty draft" do |
| 212 | login_as :quentin | 214 | login_as :quentin |
| 213 | assert_not_nil node = create_node_with_draft | 215 | assert_not_nil node = create_node_with_draft |
| 214 | get :show, params: { :id => node.id } | 216 | get :show, params: { :id => node.id } |
| 215 | assert_response :success | 217 | assert_response :success |
| 216 | end | 218 | end |
| 217 | 219 | ||
| 218 | test "show node with published draft" do | 220 | test "show node with published draft" do |
| 219 | login_as :quentin | 221 | login_as :quentin |
| 220 | node = create_node_with_published_page | 222 | node = create_node_with_published_page |
| 221 | get :show, params: { :id => node.id } | 223 | get :show, params: { :id => node.id } |
| 222 | assert_response :success | 224 | assert_response :success |
| 223 | assert_select "td", :text => "Test", :count => 3 | 225 | assert_select "div.node_content", :text => "Test", :count => 2 |
| 224 | end | 226 | end |
| 225 | 227 | ||
| 226 | test "unlocking a locked node" do | 228 | test "unlocking a locked node" do |
| 227 | login_as :quentin | 229 | login_as :quentin |
| 228 | node = create_node_with_published_page | 230 | node = create_node_with_published_page |
| 229 | node.find_or_create_draft User.first | 231 | node.find_or_create_draft User.first |
| 230 | 232 | ||
| 231 | assert node.locked? | 233 | assert node.locked? |
| 232 | 234 | ||
| 233 | put :unlock, params: { :id => node.id } | 235 | put :unlock, params: { :id => node.id } |
| 234 | assert_response :redirect | 236 | assert_response :redirect |
| 235 | assert !node.reload.locked? | 237 | assert !node.reload.locked? |
| 236 | end | 238 | end |
| 237 | 239 | ||
| 238 | test "unlocking an already unlocked node" do | 240 | test "unlocking an already unlocked node" do |
| 239 | login_as :quentin | 241 | login_as :quentin |
| 240 | node = create_node_with_published_page | 242 | node = create_node_with_published_page |
| 241 | 243 | ||
| 242 | put :unlock, params: { :id => node.id } | 244 | put :unlock, params: { :id => node.id } |
| 243 | assert_response :redirect | 245 | assert_response :redirect |
| 244 | assert_equal "Already unlocked", flash[:notice] | 246 | assert_equal "Already unlocked", flash[:notice] |
| 245 | end | 247 | end |
| 246 | 248 | ||
| 247 | test "updating a node by changing its parent" do | 249 | test "updating a node by changing its parent" do |
| 248 | Node.root.descendants.destroy_all | 250 | Node.root.descendants.destroy_all |
| 249 | login_as :quentin | 251 | login_as :quentin |
| 250 | node = create_node_with_published_page | 252 | node = create_node_with_published_page |
| 251 | node.find_or_create_draft User.first | 253 | node.find_or_create_draft User.first |
| 252 | 254 | ||
| 253 | other_node = Node.root.children.create( :slug => "other" ) | 255 | other_node = Node.root.children.create( :slug => "other" ) |
| 254 | 256 | ||
| 255 | node.staged_parent_id = other_node.id | 257 | node.staged_parent_id = other_node.id |
| 256 | node.publish_draft! | 258 | node.publish_draft! |
| 257 | 259 | ||
| 258 | assert Node.valid? | 260 | assert Node.valid? |
| 259 | end | 261 | end |
| 260 | 262 | ||
| 261 | test "editing the initial draft sets the author to current_user" do | 263 | test "editing the initial draft sets the author to current_user" do |
| 262 | login_as :quentin | 264 | login_as :quentin |
| 263 | Node.root.descendants.destroy_all | 265 | Node.root.descendants.destroy_all |
| @@ -266,7 +268,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 266 | node.reload | 268 | node.reload |
| 267 | assert_equal "quentin", node.draft.user.login | 269 | assert_equal "quentin", node.draft.user.login |
| 268 | end | 270 | end |
| 269 | 271 | ||
| 270 | test "updating the author of a node with existing head" do | 272 | test "updating the author of a node with existing head" do |
| 271 | login_as :quentin | 273 | login_as :quentin |
| 272 | Node.root.descendants.destroy_all | 274 | Node.root.descendants.destroy_all |
| @@ -275,70 +277,73 @@ class NodesControllerTest < ActionController::TestCase | |||
| 275 | node.find_or_create_draft users(:quentin) | 277 | node.find_or_create_draft users(:quentin) |
| 276 | assert node.draft.valid? | 278 | assert node.draft.valid? |
| 277 | assert node.valid? | 279 | assert node.valid? |
| 278 | 280 | ||
| 279 | put :update, params: { :id => node.id, :page => {:user_id => users(:aaron).id} } | 281 | put :update, params: { :id => node.id, :page => {:user_id => users(:aaron).id} } |
| 280 | assert_response :redirect | 282 | assert_response :redirect |
| 281 | assert_equal "aaron", node.reload.draft.user.login | 283 | assert_equal "aaron", node.reload.draft.user.login |
| 282 | end | 284 | end |
| 283 | 285 | ||
| 284 | test "updating an existing page should not modify published_at" do | 286 | test "updating an existing page should not modify published_at" do |
| 285 | login_as :quentin | 287 | login_as :quentin |
| 286 | Node.root.descendants.destroy_all | 288 | Node.root.descendants.destroy_all |
| 287 | node = create_node_with_published_page | 289 | node = create_node_with_published_page |
| 288 | 290 | ||
| 289 | get :edit, params: { :id => node.id } | 291 | get :edit, params: { :id => node.id } |
| 290 | assert_response :success | 292 | assert_response :success |
| 291 | 293 | ||
| 294 | put :update, params: { :id => node.id, :page => { :title => "updated" } } | ||
| 292 | put :publish, params: { :id => node.id } | 295 | put :publish, params: { :id => node.id } |
| 293 | 296 | ||
| 294 | node.reload | 297 | node.reload |
| 295 | assert_equal node.pages[0].published_at, node.pages[1].published_at | 298 | assert_equal node.pages[0].published_at, node.pages[1].published_at |
| 296 | end | 299 | end |
| 297 | 300 | ||
| 298 | test "updating an exisiting page should not alter the author" do | 301 | test "updating an exisiting page should not alter the author" do |
| 299 | login_as :aaron | 302 | login_as :aaron |
| 300 | Node.root.descendants.destroy_all | 303 | Node.root.descendants.destroy_all |
| 301 | node = create_node_with_published_page | 304 | node = create_node_with_published_page |
| 302 | get :edit, params: { :id => node.id } | 305 | get :edit, params: { :id => node.id } |
| 303 | 306 | ||
| 307 | put :update, params: { :id => node.id, :page => { :title => "updated" } } | ||
| 304 | put :publish, params: { :id => node.id } | 308 | put :publish, params: { :id => node.id } |
| 305 | 309 | ||
| 306 | node.reload | 310 | node.reload |
| 307 | assert_equal node.pages[0].user, node.pages[1].user | 311 | assert_equal node.pages[0].user, node.pages[1].user |
| 308 | end | 312 | end |
| 309 | 313 | ||
| 310 | test "editor and author are the same on a new node" do | 314 | test "editor and author are the same on a new node" do |
| 311 | login_as :quentin | 315 | login_as :quentin |
| 312 | node = create_node_with_draft | 316 | node = create_node_with_draft |
| 313 | get :edit, params: { :id => node.id } | 317 | get :edit, params: { :id => node.id } |
| 314 | 318 | ||
| 315 | node.reload | 319 | node.reload |
| 316 | assert_equal "quentin", node.draft.user.login | 320 | assert_equal "quentin", node.draft.user.login |
| 317 | assert_equal "quentin", node.draft.editor.login | 321 | assert_equal "quentin", node.draft.editor.login |
| 318 | end | 322 | end |
| 319 | 323 | ||
| 320 | test "creating new draft alters the editor but keeps the author" do | 324 | test "creating new draft alters the editor but keeps the author" do |
| 321 | node = create_node_with_published_page | 325 | node = create_node_with_published_page |
| 322 | assert_equal "quentin", node.head.user.login | 326 | assert_equal "quentin", node.head.user.login |
| 323 | 327 | ||
| 324 | login_as :aaron | 328 | login_as :aaron |
| 325 | get :edit, params: {:id => node.id } | 329 | get :edit, params: { :id => node.id } |
| 326 | 330 | put :update, params: { :id => node.id, :page => { :title => "updated" } } | |
| 331 | |||
| 327 | node.reload | 332 | node.reload |
| 328 | assert_equal "quentin", node.head.user.login | 333 | assert_equal "quentin", node.head.user.login |
| 329 | assert_equal "aaron", node.draft.editor.login | 334 | assert_equal "aaron", node.draft.editor.login |
| 330 | end | 335 | end |
| 331 | 336 | ||
| 332 | 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 |
| 333 | node = create_node_with_published_page | 338 | node = create_node_with_published_page |
| 334 | draft = node.find_or_create_draft users(:quentin) | 339 | draft = node.find_or_create_draft users(:quentin) |
| 335 | assert_equal draft.user.login, draft.editor.login | 340 | assert_equal draft.user.login, draft.editor.login |
| 336 | assert node.locked? | 341 | assert node.locked? |
| 337 | node.unlock! | 342 | node.unlock! |
| 338 | 343 | ||
| 339 | login_as :aaron | 344 | login_as :aaron |
| 340 | get :edit, params: { :id => node.id } | 345 | get :edit, params: { :id => node.id } |
| 341 | 346 | ||
| 342 | node.reload | 347 | node.reload |
| 343 | assert_equal "quentin", node.draft.user.login | 348 | assert_equal "quentin", node.draft.user.login |
| 344 | assert_equal "aaron", node.draft.editor.login | 349 | assert_equal "aaron", node.draft.editor.login |
| @@ -350,6 +355,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 350 | 355 | ||
| 351 | login_as :quentin | 356 | login_as :quentin |
| 352 | get :index | 357 | get :index |
| 358 | assert_response :success | ||
| 353 | end | 359 | end |
| 354 | 360 | ||
| 355 | test "no dangling pages remain after node removal" do | 361 | test "no dangling pages remain after node removal" do |
| @@ -364,7 +370,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 364 | 370 | ||
| 365 | test "can remove a node with an event" do | 371 | test "can remove a node with an event" do |
| 366 | node = create_node_with_published_page | 372 | node = create_node_with_published_page |
| 367 | Event.create!( | 373 | event = Event.create!( |
| 368 | :start_time => "2009-01-01T15:23:42".to_time, | 374 | :start_time => "2009-01-01T15:23:42".to_time, |
| 369 | :end_time => "2009-01-01T20:05:23".to_time, | 375 | :end_time => "2009-01-01T20:05:23".to_time, |
| 370 | :url => "http://events.ccc.de/congress/2082", | 376 | :url => "http://events.ccc.de/congress/2082", |
| @@ -373,10 +379,272 @@ class NodesControllerTest < ActionController::TestCase | |||
| 373 | :allday => true, | 379 | :allday => true, |
| 374 | :node_id => node.id | 380 | :node_id => node.id |
| 375 | ) | 381 | ) |
| 382 | event_id = event.id | ||
| 383 | assert_operator Occurrence.where(event_id: event_id).count, :>, 0, "expected the event to have generated at least one occurrence before destroy" | ||
| 384 | |||
| 376 | node.destroy | 385 | node.destroy |
| 377 | 386 | ||
| 387 | assert_equal 0, Occurrence.where(event_id: event_id).count | ||
| 388 | |||
| 378 | login_as :quentin | 389 | login_as :quentin |
| 379 | get :index | 390 | get :index |
| 391 | assert_response :success | ||
| 392 | end | ||
| 393 | |||
| 394 | test "show renders events row and add-link for zero-event chapter node" do | ||
| 395 | login_as :quentin | ||
| 396 | node = create_node_with_published_page | ||
| 397 | node.head.tag_list = "erfa-detail" | ||
| 398 | node.head.save! | ||
| 399 | |||
| 400 | get :show, params: { id: node.id } | ||
| 401 | assert_response :success | ||
| 402 | assert_select "a", text: "add event" | ||
| 403 | assert_select "a[href*='tag_list=open-day']" | ||
| 404 | assert_select "a[href*='auto_tag_source=erfa-detail']" | ||
| 405 | end | ||
| 406 | |||
| 407 | test "show renders events row without a tag default for untagged node" do | ||
| 408 | login_as :quentin | ||
| 409 | node = create_node_with_published_page | ||
| 410 | |||
| 411 | get :show, params: { id: node.id } | ||
| 412 | assert_response :success | ||
| 413 | assert_select "a", text: "add event" | ||
| 414 | assert_select "a[href*='tag_list=']", count: 0 | ||
| 415 | end | ||
| 416 | |||
| 417 | test "show never renders a destroy link for events" do | ||
| 418 | login_as :quentin | ||
| 419 | node = create_node_with_published_page | ||
| 420 | Event.create!(node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour) | ||
| 421 | |||
| 422 | get :show, params: { id: node.id } | ||
| 423 | assert_response :success | ||
| 424 | assert_select "form.button_to.destructive", count: 0 | ||
| 425 | end | ||
| 426 | |||
| 427 | test "reverting from nodes#show returns to the show page, not the editor, even if a draft remains" do | ||
| 428 | user = User.find_by_login("aaron") | ||
| 429 | node = Node.root.children.create!(:slug => "revert_return_to_test") | ||
| 430 | node.lock_for_editing!(user) | ||
| 431 | node.autosave!({:title => "v1"}, user) | ||
| 432 | node.save_draft!(user) | ||
| 433 | node.publish_draft! | ||
| 434 | node.lock_for_editing!(user) | ||
| 435 | node.autosave!({:title => "v2"}, user) | ||
| 436 | node.save_draft!(user) | ||
| 437 | node.lock_for_editing!(user) | ||
| 438 | node.autosave!({:title => "v3"}, user) | ||
| 439 | # state D: head, draft, and autosave all present, locked by aaron | ||
| 440 | |||
| 441 | login_as :aaron | ||
| 442 | put :revert, params: { :id => node.id, :return_to => node_path(node) } | ||
| 443 | assert_redirected_to node_path(node) | ||
| 444 | node.reload | ||
| 445 | assert node.draft.present? | ||
| 446 | assert node.autosave.blank? | ||
| 447 | end | ||
| 448 | |||
| 449 | test "reverting from nodes#edit without return_to still lands back in the editor when a draft remains" do | ||
| 450 | user = User.find_by_login("aaron") | ||
| 451 | node = Node.root.children.create!(:slug => "revert_default_test") | ||
| 452 | node.lock_for_editing!(user) | ||
| 453 | node.autosave!({:title => "v1"}, user) | ||
| 454 | node.save_draft!(user) | ||
| 455 | node.publish_draft! | ||
| 456 | node.lock_for_editing!(user) | ||
| 457 | node.autosave!({:title => "v2"}, user) | ||
| 458 | node.save_draft!(user) | ||
| 459 | node.lock_for_editing!(user) | ||
| 460 | node.autosave!({:title => "v3"}, user) | ||
| 461 | |||
| 462 | login_as :aaron | ||
| 463 | put :revert, params: { :id => node.id } | ||
| 464 | assert_redirected_to edit_node_path(node) | ||
| 465 | end | ||
| 466 | |||
| 467 | test "nodes#show does not offer to destroy the only draft of a never-published node" do | ||
| 468 | node = Node.root.children.create!(:slug => "draft_only_test") | ||
| 469 | login_as :quentin | ||
| 470 | get :show, params: { :id => node.id } | ||
| 471 | assert_response :success | ||
| 472 | assert_select "form.destructive", :count => 0 | ||
| 473 | end | ||
| 474 | |||
| 475 | test "drafts includes a never-published node with only a draft" do | ||
| 476 | node = Node.root.children.create!(:slug => "drafts_action_test") | ||
| 477 | login_as :quentin | ||
| 478 | get :drafts | ||
| 479 | assert_includes assigns(:nodes), node | ||
| 480 | end | ||
| 481 | |||
| 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") | ||
| 484 | erfa_node.find_or_create_draft(@user1) | ||
| 485 | erfa_node.draft.tag_list = "erfa-detail" | ||
| 486 | erfa_node.draft.save! | ||
| 487 | erfa_node.publish_draft! | ||
| 488 | |||
| 489 | chaostreff_node = Node.root.children.create!(:slug => "chapters_chaostreff_test") | ||
| 490 | chaostreff_node.find_or_create_draft(@user1) | ||
| 491 | chaostreff_node.draft.tag_list = "chaostreff-detail" | ||
| 492 | chaostreff_node.draft.save! | ||
| 493 | chaostreff_node.publish_draft! | ||
| 494 | |||
| 495 | login_as :quentin | ||
| 496 | |||
| 497 | get :chapters, params: { :kinds => "erfa" } | ||
| 498 | assert_includes assigns(:nodes), erfa_node | ||
| 499 | assert_not_includes assigns(:nodes), chaostreff_node | ||
| 500 | |||
| 501 | get :chapters | ||
| 502 | assert_includes assigns(:nodes), erfa_node | ||
| 503 | assert_includes assigns(:nodes), chaostreff_node | ||
| 380 | end | 504 | end |
| 381 | 505 | ||
| 506 | test "recent combined with a search term does not raise an ambiguous column error" do | ||
| 507 | login_as :quentin | ||
| 508 | get :recent, params: { :q => "Zombies" } | ||
| 509 | assert_response :success | ||
| 510 | end | ||
| 511 | |||
| 512 | test "drafts combined with a search term does not raise an ambiguous column error" do | ||
| 513 | login_as :quentin | ||
| 514 | get :drafts, params: { :q => "Zombies" } | ||
| 515 | assert_response :success | ||
| 516 | end | ||
| 517 | |||
| 518 | test "mine combined with a search term does not raise an ambiguous column error" do | ||
| 519 | login_as :quentin | ||
| 520 | get :mine, params: { :q => "Zombies" } | ||
| 521 | assert_response :success | ||
| 522 | end | ||
| 523 | |||
| 524 | test "mine shows each matching node only once, even with several revisions by the same user" do | ||
| 525 | login_as :quentin | ||
| 526 | user = User.find_by_login("quentin") | ||
| 527 | node = Node.root.children.create!(:slug => "dedup_test") | ||
| 528 | node.lock_for_editing!(user) | ||
| 529 | node.autosave!({:title => "v1"}, user) | ||
| 530 | node.save_draft!(user) | ||
| 531 | node.publish_draft! | ||
| 532 | node.lock_for_editing!(user) | ||
| 533 | node.autosave!({:title => "v2"}, user) | ||
| 534 | node.save_draft!(user) | ||
| 535 | node.publish_draft! | ||
| 536 | # three pages now exist on this node, all touched by quentin -- | ||
| 537 | # without DISTINCT, the join would return this node three times | ||
| 538 | |||
| 539 | get :mine | ||
| 540 | matches = assigns(:nodes).select { |n| n.id == node.id } | ||
| 541 | assert_equal 1, matches.length | ||
| 542 | end | ||
| 543 | |||
| 544 | test "chapters combined with a search term does not raise an ambiguous column error" do | ||
| 545 | login_as :quentin | ||
| 546 | get :chapters, params: { :q => "Zombies" } | ||
| 547 | assert_response :success | ||
| 548 | end | ||
| 549 | |||
| 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") | ||
| 552 | presse_node.find_or_create_draft(@user1) | ||
| 553 | presse_node.draft.tag_list = "pressemitteilung" | ||
| 554 | presse_node.draft.save! | ||
| 555 | presse_node.publish_draft! | ||
| 556 | |||
| 557 | erfa_node = Node.root.children.create!(:slug => "tags_path_erfa_test") | ||
| 558 | erfa_node.find_or_create_draft(@user1) | ||
| 559 | erfa_node.draft.tag_list = "erfa-detail" | ||
| 560 | erfa_node.draft.save! | ||
| 561 | erfa_node.publish_draft! | ||
| 562 | |||
| 563 | login_as :quentin | ||
| 564 | get :tags, params: { :tags => "pressemitteilung" } | ||
| 565 | |||
| 566 | assert_includes assigns(:nodes), presse_node | ||
| 567 | assert_not_includes assigns(:nodes), erfa_node | ||
| 568 | |||
| 569 | assert_select "h1", "Nodes tagged: pressemitteilung" | ||
| 570 | assert_select "h1", :text => "Chapters", :count => 0 | ||
| 571 | end | ||
| 572 | |||
| 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") | ||
| 575 | erfa_node.find_or_create_draft(@user1) | ||
| 576 | erfa_node.draft.tag_list = "erfa-detail" | ||
| 577 | erfa_node.draft.save! | ||
| 578 | erfa_node.publish_draft! | ||
| 579 | |||
| 580 | chaostreff_node = Node.root.children.create!(:slug => "tags_path_multi_chaostreff_test") | ||
| 581 | chaostreff_node.find_or_create_draft(@user1) | ||
| 582 | chaostreff_node.draft.tag_list = "chaostreff-detail" | ||
| 583 | chaostreff_node.draft.save! | ||
| 584 | chaostreff_node.publish_draft! | ||
| 585 | |||
| 586 | login_as :quentin | ||
| 587 | get :tags, params: {:tags => "erfa-detail,chaostreff-detail" } | ||
| 588 | |||
| 589 | assert_includes assigns(:nodes), erfa_node | ||
| 590 | assert_includes assigns(:nodes), chaostreff_node | ||
| 591 | end | ||
| 592 | |||
| 593 | test "chapters renders the curated heading" do | ||
| 594 | login_as :quentin | ||
| 595 | get :chapters | ||
| 596 | assert_select "h1", "Chapters" | ||
| 597 | end | ||
| 598 | |||
| 599 | test "sitemap collapses configured paths but leaves others open" do | ||
| 600 | club = Node.root.children.create!(:slug => "club") | ||
| 601 | erfas = club.children.create!(:slug => "erfas") | ||
| 602 | erfas.children.create!(:slug => "one_chapter") | ||
| 603 | other = Node.root.children.create!(:slug => "sitemap_controller_open_test") | ||
| 604 | other.children.create!(:slug => "sitemap_controller_open_child") | ||
| 605 | |||
| 606 | login_as :quentin | ||
| 607 | get :sitemap | ||
| 608 | assert_response :success | ||
| 609 | |||
| 610 | doc = Nokogiri::HTML::DocumentFragment.parse(response.body) | ||
| 611 | |||
| 612 | erfas_node_div = doc.css('.sitemap_node').find { |div| div.at_css('.field_hint')&.text&.include?(erfas.unique_name) } | ||
| 613 | other_node_div = doc.css('.sitemap_node').find { |div| div.at_css('.field_hint')&.text&.include?(other.unique_name) } | ||
| 614 | |||
| 615 | erfas_details = erfas_node_div.next_element | ||
| 616 | other_details = other_node_div.next_element | ||
| 617 | |||
| 618 | assert_equal 'details', erfas_details.name | ||
| 619 | assert_equal 'details', other_details.name | ||
| 620 | assert_not erfas_details.key?('open') | ||
| 621 | assert other_details.key?('open') | ||
| 622 | end | ||
| 623 | |||
| 624 | test "sitemap shows how many descendants a collapsed branch is hiding" do | ||
| 625 | club = Node.root.children.create!(:slug => "club") | ||
| 626 | erfas = club.children.create!(:slug => "erfas") | ||
| 627 | erfas.children.create!(:slug => "one_chapter") | ||
| 628 | erfas.children.create!(:slug => "another_chapter") | ||
| 629 | |||
| 630 | login_as :quentin | ||
| 631 | get :sitemap | ||
| 632 | assert_response :success | ||
| 633 | |||
| 634 | doc = Nokogiri::HTML::DocumentFragment.parse(response.body) | ||
| 635 | erfas_node_div = doc.css('.sitemap_node').find { |div| div.at_css('.field_hint')&.text&.include?(erfas.unique_name) } | ||
| 636 | erfas_details = erfas_node_div.next_element | ||
| 637 | |||
| 638 | assert_equal 'details', erfas_details.name | ||
| 639 | assert_match "2 descendants", erfas_details.at_css('summary').text | ||
| 640 | end | ||
| 641 | |||
| 642 | test "sitemap shows Show and Create Child, not Revisions" do | ||
| 643 | node = Node.root.children.create!(:slug => "sitemap_actions_test") | ||
| 644 | login_as :quentin | ||
| 645 | get :sitemap | ||
| 646 | assert_select ".sitemap_node_actions", :text => /Show/ | ||
| 647 | assert_select ".sitemap_node_actions", :text => /Create Child/ | ||
| 648 | assert_select ".sitemap_node_actions", :text => /Revisions/, :count => 0 | ||
| 649 | end | ||
| 382 | end | 650 | end |
