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

This commit is contained in:
Roman Rizzi 2020-05-22 11:50:28 -03:00 committed by GitHub
parent f9649c92b5
commit 671f882fa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 11 deletions

View File

@ -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

View File

@ -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