FIX: Allow users with posts to be rejected
This commit is contained in:
parent
814aee343b
commit
370355d754
|
@ -35,11 +35,14 @@ class ReviewableUser < Reviewable
|
|||
|
||||
def perform_reject(performed_by, args)
|
||||
destroyer = UserDestroyer.new(performed_by)
|
||||
destroyer.destroy(target)
|
||||
|
||||
# If a user has posts, we won't delete them to preserve their content.
|
||||
# However the reviable record will be "rejected" and they will remain
|
||||
# unapproved in the database. A staff member can still approve them
|
||||
# via the admin.
|
||||
destroyer.destroy(target) rescue UserDestroyer::PostsExistError
|
||||
|
||||
create_result(:success, :rejected)
|
||||
rescue UserDestroyer::PostsExistError
|
||||
create_result(:failed)
|
||||
end
|
||||
|
||||
# Update's the user's fields for approval but does not save. This
|
||||
|
|
|
@ -58,6 +58,20 @@ RSpec.describe ReviewableUser, type: :model do
|
|||
reviewable.reload
|
||||
expect(reviewable.target).to be_blank
|
||||
end
|
||||
|
||||
it "allows us to reject a user who has posts" do
|
||||
Fabricate(:post, user: reviewable.target)
|
||||
result = reviewable.perform(moderator, :reject)
|
||||
expect(result.success?).to eq(true)
|
||||
|
||||
expect(reviewable.pending?).to eq(false)
|
||||
expect(reviewable.rejected?).to eq(true)
|
||||
|
||||
# Rejecting deletes the user record
|
||||
reviewable.reload
|
||||
expect(reviewable.target).to be_present
|
||||
expect(reviewable.target.approved).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue