]> git.openstreetmap.org Git - rails.git/blob - test/controllers/user_blocks_controller_test.rb
Merge remote-tracking branch 'upstream/pull/4826'
[rails.git] / test / controllers / user_blocks_controller_test.rb
1 require "test_helper"
2
3 class UserBlocksControllerTest < ActionDispatch::IntegrationTest
4   ##
5   # test all routes which lead to this controller
6   def test_routes
7     assert_routing(
8       { :path => "/blocks/new/username", :method => :get },
9       { :controller => "user_blocks", :action => "new", :display_name => "username" }
10     )
11
12     assert_routing(
13       { :path => "/user_blocks", :method => :get },
14       { :controller => "user_blocks", :action => "index" }
15     )
16     assert_routing(
17       { :path => "/user_blocks/new", :method => :get },
18       { :controller => "user_blocks", :action => "new" }
19     )
20     assert_routing(
21       { :path => "/user_blocks", :method => :post },
22       { :controller => "user_blocks", :action => "create" }
23     )
24     assert_routing(
25       { :path => "/user_blocks/1", :method => :get },
26       { :controller => "user_blocks", :action => "show", :id => "1" }
27     )
28     assert_routing(
29       { :path => "/user_blocks/1/edit", :method => :get },
30       { :controller => "user_blocks", :action => "edit", :id => "1" }
31     )
32     assert_routing(
33       { :path => "/user_blocks/1", :method => :put },
34       { :controller => "user_blocks", :action => "update", :id => "1" }
35     )
36     assert_routing(
37       { :path => "/user_blocks/1", :method => :delete },
38       { :controller => "user_blocks", :action => "destroy", :id => "1" }
39     )
40     assert_routing(
41       { :path => "/blocks/1/revoke", :method => :get },
42       { :controller => "user_blocks", :action => "revoke", :id => "1" }
43     )
44     assert_routing(
45       { :path => "/blocks/1/revoke", :method => :post },
46       { :controller => "user_blocks", :action => "revoke", :id => "1" }
47     )
48
49     assert_routing(
50       { :path => "/user/username/blocks", :method => :get },
51       { :controller => "user_blocks", :action => "blocks_on", :display_name => "username" }
52     )
53     assert_routing(
54       { :path => "/user/username/blocks_by", :method => :get },
55       { :controller => "user_blocks", :action => "blocks_by", :display_name => "username" }
56     )
57     assert_routing(
58       { :path => "/user/username/blocks/revoke_all", :method => :get },
59       { :controller => "user_blocks", :action => "revoke_all", :display_name => "username" }
60     )
61     assert_routing(
62       { :path => "/user/username/blocks/revoke_all", :method => :post },
63       { :controller => "user_blocks", :action => "revoke_all", :display_name => "username" }
64     )
65   end
66
67   ##
68   # test the index action
69   def test_index
70     revoked_block = create(:user_block, :revoked)
71
72     get user_blocks_path
73     assert_response :success
74     assert_select "table#block_list tbody tr", :count => 1 do
75       assert_select "a[href='#{user_path revoked_block.user}']", :text => revoked_block.user.display_name
76       assert_select "a[href='#{user_path revoked_block.creator}']", :text => revoked_block.creator.display_name
77       assert_select "a[href='#{user_path revoked_block.revoker}']", :text => revoked_block.revoker.display_name
78     end
79
80     active_block = create(:user_block)
81     expired_block = create(:user_block, :expired)
82
83     get user_blocks_path
84     assert_response :success
85     assert_select "table#block_list tbody", :count => 1 do
86       assert_select "tr", 3
87       assert_select "a[href='#{user_block_path(active_block)}']", 1
88       assert_select "a[href='#{user_block_path(expired_block)}']", 1
89       assert_select "a[href='#{user_block_path(revoked_block)}']", 1
90     end
91   end
92
93   ##
94   # test the index action with multiple pages
95   def test_index_paged
96     user_blocks = create_list(:user_block, 50).reverse
97     next_path = user_blocks_path
98
99     get next_path
100     assert_response :success
101     check_user_blocks_table user_blocks[0...20]
102     check_no_page_link "Newer Blocks"
103     next_path = check_page_link "Older Blocks"
104
105     get next_path
106     assert_response :success
107     check_user_blocks_table user_blocks[20...40]
108     check_page_link "Newer Blocks"
109     next_path = check_page_link "Older Blocks"
110
111     get next_path
112     assert_response :success
113     check_user_blocks_table user_blocks[40...50]
114     check_page_link "Newer Blocks"
115     check_no_page_link "Older Blocks"
116   end
117
118   ##
119   # test the index action with invalid pages
120   def test_index_invalid_paged
121     %w[-1 0 fred].each do |id|
122       get user_blocks_path(:before => id)
123       assert_redirected_to :controller => :errors, :action => :bad_request
124
125       get user_blocks_path(:after => id)
126       assert_redirected_to :controller => :errors, :action => :bad_request
127     end
128   end
129
130   ##
131   # test the show action
132   def test_show
133     active_block = create(:user_block, :needs_view)
134     expired_block = create(:user_block, :expired)
135     revoked_block = create(:user_block, :revoked)
136
137     # Viewing a block should fail when a bogus ID is given
138     get user_block_path(:id => 99999)
139     assert_response :not_found
140     assert_template "not_found"
141     assert_select "p", "Sorry, the user block with ID 99999 could not be found."
142
143     # Viewing an expired block should work
144     get user_block_path(:id => expired_block)
145     assert_response :success
146     assert_select "h1 a[href='#{user_path expired_block.user}']", :text => expired_block.user.display_name
147     assert_select "h1 a[href='#{user_path expired_block.creator}']", :text => expired_block.creator.display_name
148
149     # Viewing a revoked block should work
150     get user_block_path(:id => revoked_block)
151     assert_response :success
152     assert_select "h1 a[href='#{user_path revoked_block.user}']", :text => revoked_block.user.display_name
153     assert_select "h1 a[href='#{user_path revoked_block.creator}']", :text => revoked_block.creator.display_name
154     assert_select "a[href='#{user_path revoked_block.revoker}']", :text => revoked_block.revoker.display_name
155
156     # Viewing an active block should work, but shouldn't mark it as seen
157     get user_block_path(:id => active_block)
158     assert_response :success
159     assert_select "h1 a[href='#{user_path active_block.user}']", :text => active_block.user.display_name
160     assert_select "h1 a[href='#{user_path active_block.creator}']", :text => active_block.creator.display_name
161     assert UserBlock.find(active_block.id).needs_view
162
163     # Login as the blocked user
164     session_for(active_block.user)
165
166     # Now viewing it should mark it as seen
167     get user_block_path(:id => active_block)
168     assert_response :success
169     assert_not UserBlock.find(active_block.id).needs_view
170   end
171
172   ##
173   # test the new action
174   def test_new
175     target_user = create(:user)
176
177     # Check that the block creation page requires us to login
178     get new_user_block_path(target_user)
179     assert_redirected_to login_path(:referer => new_user_block_path(target_user))
180
181     # Login as a normal user
182     session_for(create(:user))
183
184     # Check that normal users can't load the block creation page
185     get new_user_block_path(target_user)
186     assert_redirected_to :controller => "errors", :action => "forbidden"
187
188     # Login as a moderator
189     session_for(create(:moderator_user))
190
191     # Check that the block creation page loads for moderators
192     get new_user_block_path(target_user)
193     assert_response :success
194     assert_select "h1 a[href='#{user_path target_user}']", :text => target_user.display_name
195     assert_select "form#new_user_block", :count => 1 do
196       assert_select "textarea#user_block_reason", :count => 1
197       assert_select "select#user_block_period", :count => 1
198       assert_select "input#user_block_needs_view[type='checkbox']", :count => 1
199       assert_select "input#display_name[type='hidden']", :count => 1
200       assert_select "input[type='submit'][value='Create block']", :count => 1
201     end
202
203     # We should get an error if the user doesn't exist
204     get new_user_block_path(:display_name => "non_existent_user")
205     assert_response :not_found
206     assert_template "users/no_such_user"
207     assert_select "h1", "The user non_existent_user does not exist"
208   end
209
210   ##
211   # test the edit action
212   def test_edit
213     active_block = create(:user_block)
214
215     # Check that the block edit page requires us to login
216     get edit_user_block_path(:id => active_block)
217     assert_redirected_to login_path(:referer => edit_user_block_path(active_block))
218
219     # Login as a normal user
220     session_for(create(:user))
221
222     # Check that normal users can't load the block edit page
223     get edit_user_block_path(:id => active_block)
224     assert_redirected_to :controller => "errors", :action => "forbidden"
225
226     # Login as a moderator
227     session_for(create(:moderator_user))
228
229     # Check that the block edit page loads for moderators
230     get edit_user_block_path(:id => active_block)
231     assert_response :success
232     assert_select "h1 a[href='#{user_path active_block.user}']", :text => active_block.user.display_name
233     assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do
234       assert_select "textarea#user_block_reason", :count => 1
235       assert_select "select#user_block_period", :count => 1
236       assert_select "input#user_block_needs_view[type='checkbox']", :count => 1
237       assert_select "input[type='submit'][value='Update block']", :count => 1
238     end
239
240     # We should get an error if the user doesn't exist
241     get edit_user_block_path(:id => 99999)
242     assert_response :not_found
243     assert_template "not_found"
244     assert_select "p", "Sorry, the user block with ID 99999 could not be found."
245   end
246
247   ##
248   # test the create action
249   def test_create
250     target_user = create(:user)
251     moderator_user = create(:moderator_user)
252
253     # Not logged in yet, so creating a block should fail
254     post user_blocks_path
255     assert_response :forbidden
256
257     # Login as a normal user
258     session_for(create(:user))
259
260     # Check that normal users can't create blocks
261     post user_blocks_path
262     assert_redirected_to :controller => "errors", :action => "forbidden"
263
264     # Login as a moderator
265     session_for(moderator_user)
266
267     # A bogus block period should result in an error
268     assert_no_difference "UserBlock.count" do
269       post user_blocks_path(:display_name => target_user.display_name,
270                             :user_block_period => "99")
271     end
272     assert_redirected_to new_user_block_path(target_user)
273     assert_equal "The blocking period must be one of the values selectable in the drop-down list.", flash[:error]
274
275     # Check that creating a block works
276     assert_difference "UserBlock.count", 1 do
277       post user_blocks_path(:display_name => target_user.display_name,
278                             :user_block_period => "12",
279                             :user_block => { :needs_view => false, :reason => "Vandalism" })
280     end
281     id = UserBlock.order(:id).ids.last
282     assert_redirected_to user_block_path(:id => id)
283     assert_equal "Created a block on user #{target_user.display_name}.", flash[:notice]
284     b = UserBlock.find(id)
285     assert_in_delta Time.now.utc, b.created_at, 1
286     assert_in_delta Time.now.utc, b.updated_at, 1
287     assert_in_delta Time.now.utc + 12.hours, b.ends_at, 1
288     assert_not b.needs_view
289     assert_equal "Vandalism", b.reason
290     assert_equal "markdown", b.reason_format
291     assert_equal moderator_user.id, b.creator_id
292
293     # We should get an error if no user is specified
294     post user_blocks_path
295     assert_response :not_found
296     assert_template "users/no_such_user"
297     assert_select "h1", "The user  does not exist"
298
299     # We should get an error if the user doesn't exist
300     post user_blocks_path(:display_name => "non_existent_user")
301     assert_response :not_found
302     assert_template "users/no_such_user"
303     assert_select "h1", "The user non_existent_user does not exist"
304   end
305
306   ##
307   # test the duration of a created block
308   def test_create_duration
309     target_user = create(:user)
310     moderator_user = create(:moderator_user)
311
312     session_for(moderator_user)
313     post user_blocks_path(:display_name => target_user.display_name,
314                           :user_block_period => "336",
315                           :user_block => { :needs_view => false, :reason => "Vandalism" })
316
317     block = UserBlock.order(:id).last
318     assert_equal 1209600, block.ends_at - block.created_at
319   end
320
321   ##
322   # test the update action
323   def test_update
324     moderator_user = create(:moderator_user)
325     second_moderator_user = create(:moderator_user)
326     active_block = create(:user_block, :creator => moderator_user)
327
328     # Not logged in yet, so updating a block should fail
329     put user_block_path(:id => active_block)
330     assert_response :forbidden
331
332     # Login as a normal user
333     session_for(create(:user))
334
335     # Check that normal users can't update blocks
336     put user_block_path(:id => active_block)
337     assert_redirected_to :controller => "errors", :action => "forbidden"
338
339     # Login as the wrong moderator
340     session_for(second_moderator_user)
341
342     # Check that only the person who created a block can update it
343     assert_no_difference "UserBlock.count" do
344       put user_block_path(:id => active_block,
345                           :user_block_period => "12",
346                           :user_block => { :needs_view => true, :reason => "Vandalism" })
347     end
348     assert_redirected_to edit_user_block_path(active_block)
349     assert_equal "Only the moderator who created this block can edit it.", flash[:error]
350
351     # Login as the correct moderator
352     session_for(moderator_user)
353
354     # A bogus block period should result in an error
355     assert_no_difference "UserBlock.count" do
356       put user_block_path(:id => active_block, :user_block_period => "99")
357     end
358     assert_redirected_to edit_user_block_path(active_block)
359     assert_equal "The blocking period must be one of the values selectable in the drop-down list.", flash[:error]
360
361     # Check that updating a block works
362     assert_no_difference "UserBlock.count" do
363       put user_block_path(:id => active_block,
364                           :user_block_period => "12",
365                           :user_block => { :needs_view => true, :reason => "Vandalism" })
366     end
367     assert_redirected_to user_block_path(active_block)
368     assert_equal "Block updated.", flash[:notice]
369     b = UserBlock.find(active_block.id)
370     assert_in_delta Time.now.utc, b.updated_at, 1
371     assert b.needs_view
372     assert_equal "Vandalism", b.reason
373
374     # We should get an error if the block doesn't exist
375     put user_block_path(:id => 99999)
376     assert_response :not_found
377     assert_template "not_found"
378     assert_select "p", "Sorry, the user block with ID 99999 could not be found."
379   end
380
381   ##
382   # test the revoke action
383   def test_revoke
384     active_block = create(:user_block)
385
386     # Check that the block revoke page requires us to login
387     get revoke_user_block_path(:id => active_block)
388     assert_redirected_to login_path(:referer => revoke_user_block_path(:id => active_block))
389
390     # Login as a normal user
391     session_for(create(:user))
392
393     # Check that normal users can't load the block revoke page
394     get revoke_user_block_path(:id => active_block)
395     assert_redirected_to :controller => "errors", :action => "forbidden"
396
397     # Login as a moderator
398     session_for(create(:moderator_user))
399
400     # Check that the block revoke page loads for moderators
401     get revoke_user_block_path(:id => active_block)
402     assert_response :success
403     assert_template "revoke"
404     assert_select "h1 a[href='#{user_path active_block.user}']", :text => active_block.user.display_name
405     assert_select "form", :count => 1 do
406       assert_select "input#confirm[type='checkbox']", :count => 1
407       assert_select "input[type='submit'][value='Revoke!']", :count => 1
408     end
409
410     # Check that revoking a block using GET should fail
411     get revoke_user_block_path(:id => active_block, :confirm => true)
412     assert_response :success
413     assert_template "revoke"
414     b = UserBlock.find(active_block.id)
415     assert_operator b.ends_at - Time.now.utc, :>, 100
416
417     # Check that revoking a block works using POST
418     post revoke_user_block_path(:id => active_block, :confirm => true)
419     assert_redirected_to user_block_path(active_block)
420     b = UserBlock.find(active_block.id)
421     assert_in_delta Time.now.utc, b.ends_at, 1
422
423     # We should get an error if the block doesn't exist
424     get revoke_user_block_path(:id => 99999)
425     assert_response :not_found
426     assert_template "not_found"
427     assert_select "p", "Sorry, the user block with ID 99999 could not be found."
428   end
429
430   ##
431   # test the revoke all page
432   def test_revoke_all_page
433     blocked_user = create(:user)
434     create(:user_block, :user => blocked_user)
435
436     # Asking for the revoke all blocks page with a bogus user name should fail
437     get user_blocks_on_path("non_existent_user")
438     assert_response :not_found
439
440     # Check that the revoke all blocks page requires us to login
441     get revoke_all_user_blocks_path(blocked_user)
442     assert_redirected_to login_path(:referer => revoke_all_user_blocks_path(blocked_user))
443
444     # Login as a normal user
445     session_for(create(:user))
446
447     # Check that normal users can't load the revoke all blocks page
448     get revoke_all_user_blocks_path(blocked_user)
449     assert_redirected_to :controller => "errors", :action => "forbidden"
450
451     # Login as a moderator
452     session_for(create(:moderator_user))
453
454     # Check that the revoke all blocks page loads for moderators
455     get revoke_all_user_blocks_path(blocked_user)
456     assert_response :success
457     assert_select "h1 a[href='#{user_path blocked_user}']", :text => blocked_user.display_name
458   end
459
460   ##
461   # test the revoke all action
462   def test_revoke_all_action
463     blocked_user = create(:user)
464     active_block1 = create(:user_block, :user => blocked_user)
465     active_block2 = create(:user_block, :user => blocked_user)
466     expired_block1 = create(:user_block, :expired, :user => blocked_user)
467     blocks = [active_block1, active_block2, expired_block1]
468     moderator_user = create(:moderator_user)
469
470     assert_predicate active_block1, :active?
471     assert_predicate active_block2, :active?
472     assert_not_predicate expired_block1, :active?
473
474     # Login as a normal user
475     session_for(create(:user))
476
477     # Check that normal users can't load the block revoke page
478     get revoke_all_user_blocks_path(:blocked_user)
479     assert_redirected_to :controller => "errors", :action => "forbidden"
480
481     # Login as a moderator
482     session_for(moderator_user)
483
484     # Check that revoking blocks using GET should fail
485     get revoke_all_user_blocks_path(blocked_user, :confirm => true)
486     assert_response :success
487     assert_template "revoke_all"
488
489     blocks.each(&:reload)
490     assert_predicate active_block1, :active?
491     assert_predicate active_block2, :active?
492     assert_not_predicate expired_block1, :active?
493
494     # Check that revoking blocks works using POST
495     post revoke_all_user_blocks_path(blocked_user, :confirm => true)
496     assert_redirected_to user_blocks_on_path(blocked_user)
497
498     blocks.each(&:reload)
499     assert_not_predicate active_block1, :active?
500     assert_not_predicate active_block2, :active?
501     assert_not_predicate expired_block1, :active?
502     assert_equal moderator_user, active_block1.revoker
503     assert_equal moderator_user, active_block2.revoker
504     assert_not_equal moderator_user, expired_block1.revoker
505   end
506
507   ##
508   # test the blocks_on action
509   def test_blocks_on
510     blocked_user = create(:user)
511     unblocked_user = create(:user)
512     normal_user = create(:user)
513     active_block = create(:user_block, :user => blocked_user)
514     revoked_block = create(:user_block, :revoked, :user => blocked_user)
515     expired_block = create(:user_block, :expired, :user => unblocked_user)
516
517     # Asking for a list of blocks with a bogus user name should fail
518     get user_blocks_on_path("non_existent_user")
519     assert_response :not_found
520     assert_template "users/no_such_user"
521     assert_select "h1", "The user non_existent_user does not exist"
522
523     # Check the list of blocks for a user that has never been blocked
524     get user_blocks_on_path(normal_user)
525     assert_response :success
526     assert_select "table#block_list", false
527     assert_select "p", "#{normal_user.display_name} has not been blocked yet."
528
529     # Check the list of blocks for a user that is currently blocked
530     get user_blocks_on_path(blocked_user)
531     assert_response :success
532     assert_select "h1 a[href='#{user_path blocked_user}']", :text => blocked_user.display_name
533     assert_select "table#block_list tbody", :count => 1 do
534       assert_select "tr", 2
535       assert_select "a[href='#{user_block_path(active_block)}']", 1
536       assert_select "a[href='#{user_block_path(revoked_block)}']", 1
537     end
538
539     # Check the list of blocks for a user that has previously been blocked
540     get user_blocks_on_path(unblocked_user)
541     assert_response :success
542     assert_select "h1 a[href='#{user_path unblocked_user}']", :text => unblocked_user.display_name
543     assert_select "table#block_list tbody", :count => 1 do
544       assert_select "tr", 1
545       assert_select "a[href='#{user_block_path(expired_block)}']", 1
546     end
547   end
548
549   ##
550   # test the blocks_on action with multiple pages
551   def test_blocks_on_paged
552     user = create(:user)
553     user_blocks = create_list(:user_block, 50, :user => user).reverse
554     next_path = user_blocks_on_path(user)
555
556     get next_path
557     assert_response :success
558     check_user_blocks_table user_blocks[0...20]
559     check_no_page_link "Newer Blocks"
560     next_path = check_page_link "Older Blocks"
561
562     get next_path
563     assert_response :success
564     check_user_blocks_table user_blocks[20...40]
565     check_page_link "Newer Blocks"
566     next_path = check_page_link "Older Blocks"
567
568     get next_path
569     assert_response :success
570     check_user_blocks_table user_blocks[40...50]
571     check_page_link "Newer Blocks"
572     check_no_page_link "Older Blocks"
573   end
574
575   ##
576   # test the blocks_on action with invalid pages
577   def test_blocks_on_invalid_paged
578     user = create(:user)
579
580     %w[-1 0 fred].each do |id|
581       get user_blocks_on_path(user, :before => id)
582       assert_redirected_to :controller => :errors, :action => :bad_request
583
584       get user_blocks_on_path(user, :after => id)
585       assert_redirected_to :controller => :errors, :action => :bad_request
586     end
587   end
588
589   ##
590   # test the blocks_by action
591   def test_blocks_by
592     moderator_user = create(:moderator_user)
593     second_moderator_user = create(:moderator_user)
594     normal_user = create(:user)
595     active_block = create(:user_block, :creator => moderator_user)
596     expired_block = create(:user_block, :expired, :creator => second_moderator_user)
597     revoked_block = create(:user_block, :revoked, :creator => second_moderator_user)
598
599     # Asking for a list of blocks with a bogus user name should fail
600     get user_blocks_by_path("non_existent_user")
601     assert_response :not_found
602     assert_template "users/no_such_user"
603     assert_select "h1", "The user non_existent_user does not exist"
604
605     # Check the list of blocks given by one moderator
606     get user_blocks_by_path(moderator_user)
607     assert_response :success
608     assert_select "h1 a[href='#{user_path moderator_user}']", :text => moderator_user.display_name
609     assert_select "table#block_list tbody", :count => 1 do
610       assert_select "tr", 1
611       assert_select "a[href='#{user_block_path(active_block)}']", 1
612     end
613
614     # Check the list of blocks given by a different moderator
615     get user_blocks_by_path(second_moderator_user)
616     assert_response :success
617     assert_select "h1 a[href='#{user_path second_moderator_user}']", :text => second_moderator_user.display_name
618     assert_select "table#block_list tbody", :count => 1 do
619       assert_select "tr", 2
620       assert_select "a[href='#{user_block_path(expired_block)}']", 1
621       assert_select "a[href='#{user_block_path(revoked_block)}']", 1
622     end
623
624     # Check the list of blocks (not) given by a normal user
625     get user_blocks_by_path(normal_user)
626     assert_response :success
627     assert_select "table#block_list", false
628     assert_select "p", "#{normal_user.display_name} has not made any blocks yet."
629   end
630
631   ##
632   # test the blocks_by action with multiple pages
633   def test_blocks_by_paged
634     user = create(:moderator_user)
635     user_blocks = create_list(:user_block, 50, :creator => user).reverse
636     next_path = user_blocks_by_path(user)
637
638     get next_path
639     assert_response :success
640     check_user_blocks_table user_blocks[0...20]
641     check_no_page_link "Newer Blocks"
642     next_path = check_page_link "Older Blocks"
643
644     get next_path
645     assert_response :success
646     check_user_blocks_table user_blocks[20...40]
647     check_page_link "Newer Blocks"
648     next_path = check_page_link "Older Blocks"
649
650     get next_path
651     assert_response :success
652     check_user_blocks_table user_blocks[40...50]
653     check_page_link "Newer Blocks"
654     check_no_page_link "Older Blocks"
655   end
656
657   ##
658   # test the blocks_by action with invalid pages
659   def test_blocks_by_invalid_paged
660     user = create(:moderator_user)
661
662     %w[-1 0 fred].each do |id|
663       get user_blocks_by_path(user, :before => id)
664       assert_redirected_to :controller => :errors, :action => :bad_request
665
666       get user_blocks_by_path(user, :after => id)
667       assert_redirected_to :controller => :errors, :action => :bad_request
668     end
669   end
670
671   private
672
673   def check_user_blocks_table(user_blocks)
674     assert_dom "table#block_list tbody tr" do |rows|
675       assert_equal user_blocks.count, rows.count, "unexpected number of rows in user blocks table"
676       rows.zip(user_blocks).map do |row, user_block|
677         assert_dom row, "a[href='#{user_block_path user_block}']", 1
678       end
679     end
680   end
681
682   def check_no_page_link(name)
683     assert_select "a.page-link", { :text => /#{Regexp.quote(name)}/, :count => 0 }, "unexpected #{name} page link"
684   end
685
686   def check_page_link(name)
687     assert_select "a.page-link", { :text => /#{Regexp.quote(name)}/ }, "missing #{name} page link" do |buttons|
688       return buttons.first.attributes["href"].value
689     end
690   end
691 end