FIX: We don't create a Post object if the queued post gets rejected. We need to count review items directly. (#9856)

FIX: We don’t create a Post object if the queued post gets rejected. We need to count review items directly. (#9856)

diff --git a/app/models/user.rb b/app/models/user.rb
index 5d16284..d9678d1 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1115,10 +1115,9 @@ class User < ActiveRecord::Base
   end
 
   def number_of_rejected_posts
-    Post.with_deleted
-      .where(user_id: self.id)
-      .joins('INNER JOIN reviewables r ON posts.id = r.target_id')
-      .where(r: { status: Reviewable.statuses[:rejected], type: ReviewableQueuedPost.name })
+    ReviewableQueuedPost
+      .where(status: Reviewable.statuses[:rejected])
+      .where(created_by_id: self.id)
       .count
   end
 
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 89d5f62..4d2592c 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1578,20 +1578,15 @@ describe User do
 
     describe '#number_of_rejected_posts' do
       it 'counts rejected posts' do
-        post = Fabricate(:post, user: user)
-
-        Fabricate(:reviewable_queued_post, target: post, status: Reviewable.statuses[:rejected])
+        Fabricate(:reviewable_queued_post, created_by: user, status: Reviewable.statuses[:rejected])
 
         expect(user.number_of_rejected_posts).to eq(1)
       end
 
       it 'ignore non-rejected posts' do
-        post = Fabricate(:post, user: user)
-
-        Fabricate(:reviewable_queued_post, target: post, status: Reviewable.statuses[:approved])
+        Fabricate(:reviewable_queued_post, created_by: user, status: Reviewable.statuses[:approved])
 
         expect(user.number_of_rejected_posts).to eq(0)
-
       end
     end
   end

GitHub sha: 671f882f

This commit appears in #9856 which was approved by eviltrout. It was merged by romanrizzi.