FIX: Recalculate scores only when approving or transitioning to pending. (#13009)

Recalculating a ReviewableFlaggedPost's score after rejecting or ignoring it sets the score as 0, which means that we can't find them after reviewing. They don't surpass the minimum priority threshold and are hidden.

Additionally, we only want to use agreed flags when calculating the different priority thresholds.
This commit is contained in:
Roman Rizzi
2021-05-10 14:09:04 -03:00
committed by GitHub
parent d61573fb1b
commit d4b5a81b05
6 changed files with 58 additions and 20 deletions

View File

@ -305,6 +305,23 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
end
end
describe 'recalculating the reviewable score' do
let(:expected_score) { 8 }
let(:reviewable) { Fabricate(:reviewable_flagged_post, score: expected_score) }
it "doesn't recalculate the score after ignore" do
reviewable.perform(moderator, :ignore)
expect(reviewable.score).to eq(expected_score)
end
it "doesn't recalculate the score after disagree" do
reviewable.perform(moderator, :disagree)
expect(reviewable.score).to eq(expected_score)
end
end
def assert_pm_creation_enqueued(user_id, pm_type)
expect(Jobs::SendSystemMessage.jobs.length).to eq(1)
job = Jobs::SendSystemMessage.jobs[0]

View File

@ -35,7 +35,7 @@ RSpec.describe ReviewableScore, type: :model do
expect(rs.reload).to be_disagreed
expect(rs.reviewed_by).to eq(moderator)
expect(rs.reviewed_at).to be_present
expect(reviewable.score).to eq(0.0)
expect(reviewable.score).to eq(4.0)
end
it "increases the score by the post action type's score bonus" do