Stop updating the fav_string attribute on posts. The column still exists on the table, but is no longer used or updated. Like the pool_string in7d503f08, the fav_string was used in the past to facilitate `fav:X` searches. Posts had a hidden fav_string column that contained a list of every user who favorited the post. These were treated like fake hidden tags on the post so that a search for `fav:X` was treated like a tag search. The fav_string attribute has been unused for search purposes for a while now. It was only kept because of technicalities that required departitioning the favorites table first (340e1008e) before it could be removed. Basically, removing favorites with `@favorite.destroy` was slow because Rails always deletes object by ID, but we didn't have an index on favorites.id, and we couldn't easily add one until the favorites table was departitioned. Fixes #4652. See https://github.com/danbooru/danbooru/issues/4652#issuecomment-754993802 for more discussion of issues caused by the fav_string (in short: write amplification, post table bloat, and favorite inconsistency problems).
81 lines
2.3 KiB
Ruby
81 lines
2.3 KiB
Ruby
require 'test_helper'
|
|
|
|
class UserDeletionTest < ActiveSupport::TestCase
|
|
setup do
|
|
@request = mock
|
|
@request.stubs(:remote_ip).returns("1.1.1.1")
|
|
@request.stubs(:user_agent).returns("Firefox")
|
|
@request.stubs(:session).returns(session_id: "1234")
|
|
end
|
|
|
|
context "an invalid user deletion" do
|
|
context "for an invalid password" do
|
|
should "fail" do
|
|
@user = create(:user)
|
|
@deletion = UserDeletion.new(@user, "wrongpassword", @request)
|
|
@deletion.delete!
|
|
assert_includes(@deletion.errors[:base], "Password is incorrect")
|
|
end
|
|
end
|
|
|
|
context "for an admin" do
|
|
should "fail" do
|
|
@user = create(:admin_user)
|
|
@deletion = UserDeletion.new(@user, "password", @request)
|
|
@deletion.delete!
|
|
assert_includes(@deletion.errors[:base], "Admins cannot delete their account")
|
|
end
|
|
end
|
|
|
|
context "for a banned user" do
|
|
should "fail" do
|
|
@user = create(:banned_user)
|
|
@deletion = UserDeletion.new(@user, "password", @request)
|
|
@deletion.delete!
|
|
assert_includes(@deletion.errors[:base], "You cannot delete your account if you are banned")
|
|
end
|
|
end
|
|
end
|
|
|
|
context "a valid user deletion" do
|
|
setup do
|
|
@user = create(:user, name: "foo", email_address: build(:email_address))
|
|
@deletion = UserDeletion.new(@user, "password", @request)
|
|
end
|
|
|
|
should "blank out the email" do
|
|
@deletion.delete!
|
|
assert_nil(@user.reload.email_address)
|
|
end
|
|
|
|
should "rename the user" do
|
|
@deletion.delete!
|
|
assert_equal("user_#{@user.id}", @user.reload.name)
|
|
end
|
|
|
|
should "generate a user name change request" do
|
|
assert_difference("UserNameChangeRequest.count") do
|
|
@deletion.delete!
|
|
end
|
|
|
|
assert_equal("foo", UserNameChangeRequest.last.original_name)
|
|
assert_equal("user_#{@user.id}", UserNameChangeRequest.last.desired_name)
|
|
end
|
|
|
|
should "reset the password" do
|
|
@deletion.delete!
|
|
assert_equal(false, @user.authenticate_password("password"))
|
|
end
|
|
|
|
should "remove any favorites" do
|
|
@post = create(:post)
|
|
Favorite.create!(post: @post, user: @user)
|
|
|
|
perform_enqueued_jobs { @deletion.delete! }
|
|
|
|
assert_equal(0, Favorite.count)
|
|
assert_equal(0, @post.reload.fav_count)
|
|
end
|
|
end
|
|
end
|