2 require_relative "user_blocks/table_test_helper"
4 class UserBlocksControllerTest < ActionDispatch::IntegrationTest
5 include UserBlocks::TableTestHelper
8 # test all routes which lead to this controller
11 { :path => "/user_blocks/new/username", :method => :get },
12 { :controller => "user_blocks", :action => "new", :display_name => "username" }
16 { :path => "/user_blocks", :method => :get },
17 { :controller => "user_blocks", :action => "index" }
20 { :path => "/user_blocks", :method => :post },
21 { :controller => "user_blocks", :action => "create" }
24 { :path => "/user_blocks/1", :method => :get },
25 { :controller => "user_blocks", :action => "show", :id => "1" }
28 { :path => "/user_blocks/1/edit", :method => :get },
29 { :controller => "user_blocks", :action => "edit", :id => "1" }
32 { :path => "/user_blocks/1", :method => :put },
33 { :controller => "user_blocks", :action => "update", :id => "1" }
36 { :path => "/user_blocks/1", :method => :delete },
37 { :controller => "user_blocks", :action => "destroy", :id => "1" }
41 { :path => "/user/username/blocks/revoke_all", :method => :get },
42 { :controller => "user_blocks", :action => "revoke_all", :display_name => "username" }
45 { :path => "/user/username/blocks/revoke_all", :method => :post },
46 { :controller => "user_blocks", :action => "revoke_all", :display_name => "username" }
51 # test the index action
53 revoked_block = create(:user_block, :revoked)
56 assert_response :success
57 assert_select "table#block_list tbody tr", :count => 1 do
58 assert_select "a[href='#{user_path revoked_block.user}']", :text => revoked_block.user.display_name
59 assert_select "a[href='#{user_path revoked_block.creator}']", :text => revoked_block.creator.display_name
60 assert_select "a[href='#{user_path revoked_block.revoker}']", :text => revoked_block.revoker.display_name
63 active_block = create(:user_block)
64 expired_block = create(:user_block, :expired)
67 assert_response :success
68 assert_select "table#block_list tbody", :count => 1 do
70 assert_select "a[href='#{user_block_path(active_block)}']", 1
71 assert_select "a[href='#{user_block_path(expired_block)}']", 1
72 assert_select "a[href='#{user_block_path(revoked_block)}']", 1
77 # test the index action with multiple pages
79 user_blocks = create_list(:user_block, 50).reverse
80 next_path = user_blocks_path
83 assert_response :success
84 check_user_blocks_table user_blocks[0...20]
85 check_no_page_link "Newer Blocks"
86 next_path = check_page_link "Older Blocks"
89 assert_response :success
90 check_user_blocks_table user_blocks[20...40]
91 check_page_link "Newer Blocks"
92 next_path = check_page_link "Older Blocks"
95 assert_response :success
96 check_user_blocks_table user_blocks[40...50]
97 check_page_link "Newer Blocks"
98 check_no_page_link "Older Blocks"
102 # test the index action with invalid pages
103 def test_index_invalid_paged
104 %w[-1 0 fred].each do |id|
105 get user_blocks_path(:before => id)
106 assert_redirected_to :controller => :errors, :action => :bad_request
108 get user_blocks_path(:after => id)
109 assert_redirected_to :controller => :errors, :action => :bad_request
114 # test the show action
116 active_block = create(:user_block, :needs_view)
117 expired_block = create(:user_block, :expired)
118 revoked_block = create(:user_block, :revoked)
120 # Viewing a block should fail when a bogus ID is given
121 get user_block_path(99999)
122 assert_response :not_found
123 assert_template "not_found"
124 assert_select "p", "Sorry, the user block with ID 99999 could not be found."
126 # Viewing an expired block should work
127 get user_block_path(expired_block)
128 assert_response :success
129 assert_select "h1 a[href='#{user_path expired_block.user}']", :text => expired_block.user.display_name
130 assert_select "h1 a[href='#{user_path expired_block.creator}']", :text => expired_block.creator.display_name
132 # Viewing a revoked block should work
133 get user_block_path(revoked_block)
134 assert_response :success
135 assert_select "h1 a[href='#{user_path revoked_block.user}']", :text => revoked_block.user.display_name
136 assert_select "h1 a[href='#{user_path revoked_block.creator}']", :text => revoked_block.creator.display_name
137 assert_select "a[href='#{user_path revoked_block.revoker}']", :text => revoked_block.revoker.display_name
139 # Viewing an active block should work, but shouldn't mark it as seen
140 get user_block_path(active_block)
141 assert_response :success
142 assert_select "h1 a[href='#{user_path active_block.user}']", :text => active_block.user.display_name
143 assert_select "h1 a[href='#{user_path active_block.creator}']", :text => active_block.creator.display_name
144 assert UserBlock.find(active_block.id).needs_view
148 # test clearing needs_view by showing a zero-hour block to the blocked user
149 def test_show_sets_deactivates_at_for_zero_hour_block
154 block = create(:user_block, :needs_view, :zero_hour, :user => user)
155 assert block.needs_view
156 assert_nil block.deactivates_at
160 get user_block_path(block)
161 assert_response :success
163 assert_not block.needs_view
164 assert_equal Time.now.utc, block.deactivates_at
168 get user_block_path(block)
169 assert_response :success
171 assert_not block.needs_view
172 assert_equal Time.now.utc - 1.hour, block.deactivates_at
177 # test clearing needs_view by showing a timed block to the blocked user
178 def test_show_sets_deactivates_at_for_timed_block
183 block = create(:user_block, :needs_view, :created_at => Time.now.utc, :ends_at => Time.now.utc + 24.hours, :user => user)
184 assert block.needs_view
185 assert_nil block.deactivates_at
189 get user_block_path(block)
190 assert_response :success
192 assert_not block.needs_view
193 assert_equal Time.now.utc + 23.hours, block.deactivates_at
197 get user_block_path(block)
198 assert_response :success
200 assert_not block.needs_view
201 assert_equal Time.now.utc + 22.hours, block.deactivates_at
205 get user_block_path(block)
206 assert_response :success
208 assert_not block.needs_view
209 assert_equal Time.now.utc - 2.hours, block.deactivates_at
214 # test edit/revoke link for active blocks
215 def test_active_block_buttons
216 creator_user = create(:moderator_user)
217 other_moderator_user = create(:moderator_user)
218 block = create(:user_block, :creator => creator_user)
220 session_for(other_moderator_user)
221 check_block_buttons block, :edit => 1
223 session_for(creator_user)
224 check_block_buttons block, :edit => 1
228 # test the edit link for expired blocks
229 def test_expired_block_buttons
230 creator_user = create(:moderator_user)
231 other_moderator_user = create(:moderator_user)
232 block = create(:user_block, :expired, :creator => creator_user)
234 session_for(other_moderator_user)
235 check_block_buttons block
237 session_for(creator_user)
238 check_block_buttons block, :edit => 1
242 # test the edit link for revoked blocks
243 def test_revoked_block_buttons
244 creator_user = create(:moderator_user)
245 revoker_user = create(:moderator_user)
246 other_moderator_user = create(:moderator_user)
247 block = create(:user_block, :revoked, :creator => creator_user, :revoker => revoker_user)
249 session_for(other_moderator_user)
250 check_block_buttons block
252 session_for(creator_user)
253 check_block_buttons block, :edit => 1
255 session_for(revoker_user)
256 check_block_buttons block, :edit => 1
260 # test the new action
262 target_user = create(:user)
264 # Check that the block creation page requires us to login
265 get new_user_block_path(target_user)
266 assert_redirected_to login_path(:referer => new_user_block_path(target_user))
268 # Login as a normal user
269 session_for(create(:user))
271 # Check that normal users can't load the block creation page
272 get new_user_block_path(target_user)
273 assert_redirected_to :controller => "errors", :action => "forbidden"
275 # Login as a moderator
276 session_for(create(:moderator_user))
278 # Check that the block creation page loads for moderators
279 get new_user_block_path(target_user)
280 assert_response :success
281 assert_select "h1 a[href='#{user_path target_user}']", :text => target_user.display_name
282 assert_select "form#new_user_block", :count => 1 do
283 assert_select "textarea#user_block_reason", :count => 1
284 assert_select "select#user_block_period", :count => 1
285 assert_select "input#user_block_needs_view[type='checkbox']", :count => 1
286 assert_select "input#display_name[type='hidden']", :count => 1
287 assert_select "input[type='submit'][value='Create block']", :count => 1
290 # We should get an error if the user doesn't exist
291 get new_user_block_path("non_existent_user")
292 assert_response :not_found
293 assert_template "users/no_such_user"
294 assert_select "h1", "The user non_existent_user does not exist"
298 # test the edit action
300 creator_user = create(:moderator_user)
301 other_moderator_user = create(:moderator_user)
302 active_block = create(:user_block, :creator => creator_user)
304 # Check that the block edit page requires us to login
305 get edit_user_block_path(active_block)
306 assert_redirected_to login_path(:referer => edit_user_block_path(active_block))
308 # Login as a normal user
309 session_for(create(:user))
311 # Check that normal users can't load the block edit page
312 get edit_user_block_path(active_block)
313 assert_redirected_to :controller => "errors", :action => "forbidden"
315 # Login as a moderator
316 session_for(other_moderator_user)
318 # Check that the block edit page loads for moderators
319 get edit_user_block_path(active_block)
320 assert_response :success
321 assert_select "h1 a[href='#{user_path active_block.user}']", :text => active_block.user.display_name
322 assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do
323 assert_select "textarea#user_block_reason", :count => 1
324 assert_select "select#user_block_period", :count => 0
325 assert_select "input#user_block_needs_view[type='checkbox']", :count => 0
326 assert_select "input[type='submit'][value='Update block']", :count => 0
327 assert_select "input#user_block_period[type='hidden']", :count => 1
328 assert_select "input#user_block_needs_view[type='hidden']", :count => 1
329 assert_select "input[type='submit'][value='Revoke block']", :count => 1
332 # Login as the block creator
333 session_for(creator_user)
335 # Check that the block edit page loads for the creator
336 get edit_user_block_path(active_block)
337 assert_response :success
338 assert_select "h1 a[href='#{user_path active_block.user}']", :text => active_block.user.display_name
339 assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do
340 assert_select "textarea#user_block_reason", :count => 1
341 assert_select "select#user_block_period", :count => 1
342 assert_select "input#user_block_needs_view[type='checkbox']", :count => 1
343 assert_select "input[type='submit'][value='Update block']", :count => 1
344 assert_select "input#user_block_period[type='hidden']", :count => 0
345 assert_select "input#user_block_needs_view[type='hidden']", :count => 0
346 assert_select "input[type='submit'][value='Revoke block']", :count => 0
349 # We should get an error if the user doesn't exist
350 get edit_user_block_path(99999)
351 assert_response :not_found
352 assert_template "not_found"
353 assert_select "p", "Sorry, the user block with ID 99999 could not be found."
357 # test the edit action when the remaining block duration doesn't match the available select options
358 def test_edit_duration
359 moderator_user = create(:moderator_user)
362 active_block = create(:user_block, :creator => moderator_user, :ends_at => Time.now.utc + 96.hours)
364 session_for(moderator_user)
365 get edit_user_block_path(active_block)
367 assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do
368 assert_select "select#user_block_period", :count => 1 do
369 assert_select "option[value='96'][selected]", :count => 1
374 get edit_user_block_path(active_block)
376 assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do
377 assert_select "select#user_block_period", :count => 1 do
378 assert_select "option[value='96'][selected]", :count => 1
385 # test the create action
387 target_user = create(:user)
388 moderator_user = create(:moderator_user)
390 # Not logged in yet, so creating a block should fail
391 post user_blocks_path
392 assert_response :forbidden
394 # Login as a normal user
395 session_for(create(:user))
397 # Check that normal users can't create blocks
398 post user_blocks_path
399 assert_redirected_to :controller => "errors", :action => "forbidden"
401 # Login as a moderator
402 session_for(moderator_user)
404 # A bogus block period should result in an error
405 assert_no_difference "UserBlock.count" do
406 post user_blocks_path(:display_name => target_user.display_name,
407 :user_block_period => "99")
409 assert_redirected_to new_user_block_path(target_user)
410 assert_equal "The blocking period must be one of the values selectable in the drop-down list.", flash[:error]
412 # Check that creating a block works
413 assert_difference "UserBlock.count", 1 do
414 post user_blocks_path(:display_name => target_user.display_name,
415 :user_block_period => "12",
416 :user_block => { :needs_view => false, :reason => "Vandalism" })
419 assert_redirected_to user_block_path(b)
420 assert_equal "Created a block on user #{target_user.display_name}.", flash[:notice]
421 assert_in_delta Time.now.utc, b.created_at, 1
422 assert_in_delta Time.now.utc, b.updated_at, 1
423 assert_in_delta Time.now.utc + 12.hours, b.ends_at, 1
424 assert_not b.needs_view
425 assert_equal "Vandalism", b.reason
426 assert_equal "markdown", b.reason_format
427 assert_equal moderator_user.id, b.creator_id
429 # We should get an error if no user is specified
430 post user_blocks_path
431 assert_response :not_found
432 assert_template "users/no_such_user"
433 assert_select "h1", "The user does not exist"
435 # We should get an error if the user doesn't exist
436 post user_blocks_path(:display_name => "non_existent_user")
437 assert_response :not_found
438 assert_template "users/no_such_user"
439 assert_select "h1", "The user non_existent_user does not exist"
443 # test the duration of a created block
444 def test_create_duration
445 target_user = create(:user)
446 moderator_user = create(:moderator_user)
448 session_for(moderator_user)
449 post user_blocks_path(:display_name => target_user.display_name,
450 :user_block_period => "336",
451 :user_block => { :needs_view => false, :reason => "Vandalism" })
453 block = UserBlock.last
454 assert_equal 1209600, block.ends_at - block.created_at
458 # test the update action
460 moderator_user = create(:moderator_user)
461 active_block = create(:user_block, :creator => moderator_user)
463 # Not logged in yet, so updating a block should fail
464 put user_block_path(active_block)
465 assert_response :forbidden
467 # Login as a normal user
468 session_for(create(:user))
470 # Check that normal users can't update blocks
471 put user_block_path(active_block)
472 assert_redirected_to :controller => "errors", :action => "forbidden"
474 # Login as the moderator
475 session_for(moderator_user)
477 # A bogus block period should result in an error
478 assert_no_difference "UserBlock.count" do
479 put user_block_path(active_block, :user_block_period => "99")
481 assert_redirected_to edit_user_block_path(active_block)
482 assert_equal "The blocking period must be one of the values selectable in the drop-down list.", flash[:error]
484 # Check that updating a block works
485 assert_no_difference "UserBlock.count" do
486 put user_block_path(active_block,
487 :user_block_period => "12",
488 :user_block => { :needs_view => true, :reason => "Vandalism" })
490 assert_redirected_to user_block_path(active_block)
491 assert_equal "Block updated.", flash[:notice]
492 b = UserBlock.find(active_block.id)
493 assert_in_delta Time.now.utc, b.updated_at, 1
495 assert_equal "Vandalism", b.reason
497 # We should get an error if the block doesn't exist
498 put user_block_path(99999)
499 assert_response :not_found
500 assert_template "not_found"
501 assert_select "p", "Sorry, the user block with ID 99999 could not be found."
505 # test the update action on expired blocks
506 def test_update_expired
507 creator_user = create(:moderator_user)
508 other_moderator_user = create(:moderator_user)
509 block = create(:user_block, :expired, :creator => creator_user, :reason => "Original Reason")
511 session_for(other_moderator_user)
512 put user_block_path(block,
513 :user_block_period => "0",
514 :user_block => { :needs_view => false, :reason => "Updated Reason" })
515 assert_redirected_to edit_user_block_path(block)
516 assert_equal "Only the moderator who created this block can edit it.", flash[:error]
518 assert_not block.active?
519 assert_equal "Original Reason", block.reason
521 session_for(creator_user)
522 check_inactive_block_updates(block)
526 # test the update action on revoked blocks
527 def test_update_revoked
528 creator_user = create(:moderator_user)
529 revoker_user = create(:moderator_user)
530 other_moderator_user = create(:moderator_user)
531 block = create(:user_block, :revoked, :creator => creator_user, :revoker => revoker_user, :reason => "Original Reason")
533 session_for(other_moderator_user)
534 put user_block_path(block,
535 :user_block_period => "0",
536 :user_block => { :needs_view => false, :reason => "Updated Reason" })
537 assert_redirected_to edit_user_block_path(block)
538 assert_equal "Only the moderators who created or revoked this block can edit it.", flash[:error]
540 assert_not_predicate block, :active?
541 assert_equal "Original Reason", block.reason
543 session_for(creator_user)
544 check_inactive_block_updates(block)
546 session_for(revoker_user)
547 check_inactive_block_updates(block)
551 # test the update action revoking the block
552 def test_revoke_using_update_by_creator
553 moderator_user = create(:moderator_user)
554 block = create(:user_block, :creator => moderator_user)
556 session_for(moderator_user)
557 put user_block_path(block,
558 :user_block_period => "24",
559 :user_block => { :needs_view => false, :reason => "Updated Reason" })
560 assert_redirected_to user_block_path(block)
561 assert_equal "Block updated.", flash[:notice]
563 assert_predicate block, :active?
564 assert_nil block.revoker
566 put user_block_path(block,
567 :user_block_period => "0",
568 :user_block => { :needs_view => false, :reason => "Updated Reason" })
569 assert_redirected_to user_block_path(block)
570 assert_equal "Block updated.", flash[:notice]
572 assert_not_predicate block, :active?
573 assert_equal moderator_user, block.revoker
576 def test_revoke_using_update_by_other_moderator
577 creator_user = create(:moderator_user)
578 other_moderator_user = create(:moderator_user)
579 block = create(:user_block, :creator => creator_user)
581 session_for(other_moderator_user)
582 put user_block_path(block,
583 :user_block_period => "24",
584 :user_block => { :needs_view => false, :reason => "Updated Reason" })
585 assert_response :success
586 assert_equal "Only the moderator who created this block can edit it without revoking.", flash[:error]
588 assert_predicate block, :active?
589 assert_nil block.revoker
591 put user_block_path(block,
592 :user_block_period => "0",
593 :user_block => { :needs_view => false, :reason => "Updated Reason" })
594 assert_redirected_to user_block_path(block)
595 assert_equal "Block updated.", flash[:notice]
597 assert_not_predicate block, :active?
598 assert_equal other_moderator_user, block.revoker
602 # test the revoke all page
603 def test_revoke_all_page
604 blocked_user = create(:user)
605 create(:user_block, :user => blocked_user)
607 # Asking for the revoke all blocks page with a bogus user name should fail
608 get user_received_blocks_path("non_existent_user")
609 assert_response :not_found
611 # Check that the revoke all blocks page requires us to login
612 get revoke_all_user_blocks_path(blocked_user)
613 assert_redirected_to login_path(:referer => revoke_all_user_blocks_path(blocked_user))
615 # Login as a normal user
616 session_for(create(:user))
618 # Check that normal users can't load the revoke all blocks page
619 get revoke_all_user_blocks_path(blocked_user)
620 assert_redirected_to :controller => "errors", :action => "forbidden"
622 # Login as a moderator
623 session_for(create(:moderator_user))
625 # Check that the revoke all blocks page loads for moderators
626 get revoke_all_user_blocks_path(blocked_user)
627 assert_response :success
628 assert_select "h1 a[href='#{user_path blocked_user}']", :text => blocked_user.display_name
632 # test the revoke all action
633 def test_revoke_all_action
634 blocked_user = create(:user)
635 active_block1 = create(:user_block, :user => blocked_user)
636 active_block2 = create(:user_block, :user => blocked_user)
637 expired_block1 = create(:user_block, :expired, :user => blocked_user)
638 blocks = [active_block1, active_block2, expired_block1]
639 moderator_user = create(:moderator_user)
641 assert_predicate active_block1, :active?
642 assert_predicate active_block2, :active?
643 assert_not_predicate expired_block1, :active?
645 # Login as a normal user
646 session_for(create(:user))
648 # Check that normal users can't load the block revoke page
649 get revoke_all_user_blocks_path(:blocked_user)
650 assert_redirected_to :controller => "errors", :action => "forbidden"
652 # Login as a moderator
653 session_for(moderator_user)
655 # Check that revoking blocks using GET should fail
656 get revoke_all_user_blocks_path(blocked_user, :confirm => true)
657 assert_response :success
658 assert_template "revoke_all"
660 blocks.each(&:reload)
661 assert_predicate active_block1, :active?
662 assert_predicate active_block2, :active?
663 assert_not_predicate expired_block1, :active?
665 # Check that revoking blocks works using POST
666 post revoke_all_user_blocks_path(blocked_user, :confirm => true)
667 assert_redirected_to user_received_blocks_path(blocked_user)
669 blocks.each(&:reload)
670 assert_not_predicate active_block1, :active?
671 assert_not_predicate active_block2, :active?
672 assert_not_predicate expired_block1, :active?
673 assert_equal moderator_user, active_block1.revoker
674 assert_equal moderator_user, active_block2.revoker
675 assert_not_equal moderator_user, expired_block1.revoker
679 # test changes to end/deactivation dates
680 def test_dates_when_viewed_before_end
681 blocked_user = create(:user)
682 moderator_user = create(:moderator_user)
685 session_for(moderator_user)
686 assert_difference "UserBlock.count", 1 do
687 post user_blocks_path(:display_name => blocked_user.display_name,
688 :user_block_period => "48",
689 :user_block => { :needs_view => true, :reason => "Testing deactivates_at" })
691 block = UserBlock.last
692 assert_equal Time.now.utc + 48.hours, block.ends_at
693 assert_nil block.deactivates_at
696 session_for(blocked_user)
697 get user_block_path(block)
699 assert_equal Time.now.utc + 24.hours, block.ends_at
700 assert_equal Time.now.utc + 24.hours, block.deactivates_at
704 def test_dates_when_viewed_after_end
705 blocked_user = create(:user)
706 moderator_user = create(:moderator_user)
709 session_for(moderator_user)
710 assert_difference "UserBlock.count", 1 do
711 post user_blocks_path(:display_name => blocked_user.display_name,
712 :user_block_period => "24",
713 :user_block => { :needs_view => true, :reason => "Testing deactivates_at" })
715 block = UserBlock.last
716 assert_equal Time.now.utc + 24.hours, block.ends_at
717 assert_nil block.deactivates_at
720 session_for(blocked_user)
721 get user_block_path(block)
723 assert_equal Time.now.utc - 24.hours, block.ends_at
724 assert_equal Time.now.utc, block.deactivates_at
728 def test_dates_when_edited_before_end
729 blocked_user = create(:user)
730 moderator_user = create(:moderator_user)
733 session_for(moderator_user)
734 assert_difference "UserBlock.count", 1 do
735 post user_blocks_path(:display_name => blocked_user.display_name,
736 :user_block_period => "48",
737 :user_block => { :needs_view => false, :reason => "Testing deactivates_at" })
739 block = UserBlock.last
740 assert_equal Time.now.utc + 48.hours, block.ends_at
741 assert_equal Time.now.utc + 48.hours, block.deactivates_at
744 put user_block_path(block,
745 :user_block_period => "48",
746 :user_block => { :needs_view => false, :reason => "Testing deactivates_at updated" })
748 assert_equal Time.now.utc + 48.hours, block.ends_at
749 assert_equal Time.now.utc + 48.hours, block.deactivates_at
753 def test_dates_when_edited_after_end
754 blocked_user = create(:user)
755 moderator_user = create(:moderator_user)
758 session_for(moderator_user)
759 assert_difference "UserBlock.count", 1 do
760 post user_blocks_path(:display_name => blocked_user.display_name,
761 :user_block_period => "24",
762 :user_block => { :needs_view => false, :reason => "Testing deactivates_at" })
764 block = UserBlock.last
765 assert_equal Time.now.utc + 24.hours, block.ends_at
766 assert_equal Time.now.utc + 24.hours, block.deactivates_at
769 put user_block_path(block,
770 :user_block_period => "0",
771 :user_block => { :needs_view => false, :reason => "Testing deactivates_at updated" })
773 assert_equal Time.now.utc - 24.hours, block.ends_at
774 assert_equal Time.now.utc - 24.hours, block.deactivates_at
779 # test updates on legacy records without correctly initialized deactivates_at
780 def test_update_legacy_deactivates_at
781 blocked_user = create(:user)
782 moderator_user = create(:moderator_user)
785 block = UserBlock.new :user => blocked_user,
786 :creator => moderator_user,
787 :reason => "because",
788 :ends_at => Time.now.utc + 24.hours,
791 assert_difference "UserBlock.count", 1 do
792 block.save :validate => false
796 session_for(moderator_user)
797 put user_block_path(block,
798 :user_block_period => "0",
799 :user_block => { :needs_view => false, :reason => "Testing legacy block update" })
801 assert_equal Time.now.utc - 24.hours, block.ends_at
802 assert_equal Time.now.utc - 24.hours, block.deactivates_at
808 def check_block_buttons(block, edit: 0)
809 [user_blocks_path, user_block_path(block)].each do |path|
811 assert_response :success
812 assert_select "a[href='#{edit_user_block_path block}']", :count => edit
816 def check_inactive_block_updates(block)
817 original_ends_at = block.ends_at
819 put user_block_path(block,
820 :user_block_period => "0",
821 :user_block => { :needs_view => false, :reason => "Updated Reason" })
822 assert_redirected_to user_block_path(block)
823 assert_equal "Block updated.", flash[:notice]
825 assert_not_predicate block, :active?
826 assert_equal "Updated Reason", block.reason
827 assert_equal original_ends_at, block.ends_at
829 put user_block_path(block,
830 :user_block_period => "0",
831 :user_block => { :needs_view => true, :reason => "Updated Reason Needs View" })
832 assert_response :success
833 assert_equal "This block is inactive and cannot be reactivated.", flash[:error]
835 assert_not_predicate block, :active?
836 assert_equal "Updated Reason", block.reason
837 assert_equal original_ends_at, block.ends_at
839 put user_block_path(block,
840 :user_block_period => "1",
841 :user_block => { :needs_view => false, :reason => "Updated Reason Duration Extended" })
842 assert_response :success
843 assert_equal "This block is inactive and cannot be reactivated.", flash[:error]
845 assert_not_predicate block, :active?
846 assert_equal "Updated Reason", block.reason
847 assert_equal original_ends_at, block.ends_at
849 put user_block_path(block,
850 :user_block_period => "0",
851 :user_block => { :needs_view => false, :reason => "Updated Reason Again" })
852 assert_redirected_to user_block_path(block)
853 assert_equal "Block updated.", flash[:notice]
855 assert_not_predicate block, :active?
856 assert_equal "Updated Reason Again", block.reason
857 assert_equal original_ends_at, block.ends_at