FIX: Accurate sub_total calculation for reviewable_scores (#8184)

This commit is contained in:
Mark VanLandingham
2019-10-11 11:07:19 -05:00
committed by GitHub
parent 76ab0350f1
commit f63db1c4c8
3 changed files with 29 additions and 10 deletions

View File

@ -145,7 +145,6 @@ RSpec.describe ReviewableScore, type: :model do
user_stat.flags_disagreed = 12
expect(ReviewableScore.user_accuracy_bonus(user).floor(2)).to eq(12.27)
end
end
describe ".user_flag_score" do
@ -172,13 +171,29 @@ RSpec.describe ReviewableScore, type: :model do
user_stat.flags_ignored = 2
expect(ReviewableScore.user_flag_score(user).floor(2)).to eq(7.99)
end
end
end
it 'return 0 if the accuracy_bonus would make the score negative' do
user.trust_level = 3
user_stat.flags_agreed = 0
user_stat.flags_disagreed = 1000
expect(ReviewableScore.user_flag_score(user)).to eq(0)
end
describe ".calculate_score" do
fab!(:user) { Fabricate(:user) }
let(:user_stat) { user.user_stat }
it 'never returns less than 0' do
user.trust_level = 2
user_stat.flags_agreed = 1
user_stat.flags_disagreed = 1000
flag_score = -21.88
expect(ReviewableScore.user_flag_score(user).floor(2)).to eq(flag_score)
expect(ReviewableScore.calculate_score(user, 5, 5)).to eq(0)
end
it 'returns user_flag_score + type_bonus + take_action_bonus' do
user.trust_level = 2
user_stat.flags_agreed = 12
user_stat.flags_disagreed = 2
flag_score = 7.99
expect(ReviewableScore.user_flag_score(user).floor(2)).to eq(flag_score)
expect(ReviewableScore.calculate_score(user, 2, 3)).to eq(flag_score + 2 + 3)
end
end