FIX: Allow users with posts to be rejected

FIX: Allow users with posts to be rejected

diff --git a/app/models/reviewable_user.rb b/app/models/reviewable_user.rb
index b1778d4..1f4f7a0 100644
--- a/app/models/reviewable_user.rb
+++ b/app/models/reviewable_user.rb
@@ -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
diff --git a/spec/models/reviewable_user_spec.rb b/spec/models/reviewable_user_spec.rb
index f35edff..0dddff8 100644
--- a/spec/models/reviewable_user_spec.rb
+++ b/spec/models/reviewable_user_spec.rb
@@ -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

GitHub sha: 370355d7

This commit has been mentioned on Discourse Meta. There might be relevant details there: