+ ##
+ # test the update action on revoked blocks
+ def test_update_revoked
+ creator_user = create(:moderator_user)
+ revoker_user = create(:moderator_user)
+ other_moderator_user = create(:moderator_user)
+ block = create(:user_block, :revoked, :creator => creator_user, :revoker => revoker_user, :reason => "Original Reason")
+
+ session_for(other_moderator_user)
+ put user_block_path(block,
+ :user_block_period => "0",
+ :user_block => { :needs_view => false, :reason => "Updated Reason" })
+ assert_redirected_to edit_user_block_path(block)
+ assert_equal "Only the moderators who created or revoked this block can edit it.", flash[:error]
+ block.reload
+ assert_not_predicate block, :active?
+ assert_equal "Original Reason", block.reason
+
+ session_for(creator_user)
+ check_inactive_block_updates(block)
+
+ session_for(revoker_user)
+ check_inactive_block_updates(block)
+ end
+
+ ##
+ # test the update action revoking the block
+ def test_revoke_using_update_by_creator
+ moderator_user = create(:moderator_user)
+ block = create(:user_block, :creator => moderator_user)
+
+ session_for(moderator_user)
+ put user_block_path(block,
+ :user_block_period => "24",
+ :user_block => { :needs_view => false, :reason => "Updated Reason" })
+ assert_redirected_to user_block_path(block)
+ assert_equal "Block updated.", flash[:notice]
+ block.reload
+ assert_predicate block, :active?
+ assert_nil block.revoker
+
+ put user_block_path(block,
+ :user_block_period => "0",
+ :user_block => { :needs_view => false, :reason => "Updated Reason" })
+ assert_redirected_to user_block_path(block)
+ assert_equal "Block updated.", flash[:notice]
+ block.reload
+ assert_not_predicate block, :active?
+ assert_equal moderator_user, block.revoker
+ end
+
+ def test_revoke_using_update_by_other_moderator
+ creator_user = create(:moderator_user)
+ other_moderator_user = create(:moderator_user)
+ block = create(:user_block, :creator => creator_user)
+
+ session_for(other_moderator_user)
+ put user_block_path(block,
+ :user_block_period => "24",
+ :user_block => { :needs_view => false, :reason => "Updated Reason" })
+ assert_response :success
+ assert_equal "Only the moderator who created this block can edit it without revoking.", flash[:error]
+ block.reload
+ assert_predicate block, :active?
+ assert_nil block.revoker
+
+ put user_block_path(block,
+ :user_block_period => "0",
+ :user_block => { :needs_view => false, :reason => "Updated Reason" })
+ assert_redirected_to user_block_path(block)
+ assert_equal "Block updated.", flash[:notice]
+ block.reload
+ assert_not_predicate block, :active?
+ assert_equal other_moderator_user, block.revoker
+ end
+
+ ##
+ # test the revoke all page
+ def test_revoke_all_page
+ blocked_user = create(:user)
+ create(:user_block, :user => blocked_user)
+
+ # Asking for the revoke all blocks page with a bogus user name should fail
+ get user_blocks_on_path("non_existent_user")
+ assert_response :not_found
+
+ # Check that the revoke all blocks page requires us to login
+ get revoke_all_user_blocks_path(blocked_user)
+ assert_redirected_to login_path(:referer => revoke_all_user_blocks_path(blocked_user))
+
+ # Login as a normal user
+ session_for(create(:user))
+
+ # Check that normal users can't load the revoke all blocks page
+ get revoke_all_user_blocks_path(blocked_user)
+ assert_redirected_to :controller => "errors", :action => "forbidden"
+
+ # Login as a moderator
+ session_for(create(:moderator_user))
+
+ # Check that the revoke all blocks page loads for moderators
+ get revoke_all_user_blocks_path(blocked_user)
+ assert_response :success
+ assert_select "h1 a[href='#{user_path blocked_user}']", :text => blocked_user.display_name
+ end
+
+ ##
+ # test the revoke all action
+ def test_revoke_all_action
+ blocked_user = create(:user)
+ active_block1 = create(:user_block, :user => blocked_user)
+ active_block2 = create(:user_block, :user => blocked_user)
+ expired_block1 = create(:user_block, :expired, :user => blocked_user)
+ blocks = [active_block1, active_block2, expired_block1]
+ moderator_user = create(:moderator_user)
+
+ assert_predicate active_block1, :active?
+ assert_predicate active_block2, :active?
+ assert_not_predicate expired_block1, :active?