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:
parent
f9649c92b5
commit
671f882fa3
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue