adds confidence_score capacity to the comment model

This commit is contained in:
kikito
2015-10-28 16:25:35 +01:00
parent da19d4d773
commit f5d9ea4357
3 changed files with 50 additions and 0 deletions

View File

@@ -39,6 +39,44 @@ describe Comment do
end
end
describe "#confidence_score" do
it "takes into account percentage of total votes and total_positive and total negative votes" do
comment = create(:comment, :with_confidence_score, cached_votes_up: 100, cached_votes_total: 100)
expect(comment.confidence_score).to eq(10000)
comment = create(:comment, :with_confidence_score, cached_votes_up: 0, cached_votes_total: 100)
expect(comment.confidence_score).to eq(0)
comment = create(:comment, :with_confidence_score, cached_votes_up: 75, cached_votes_total: 100)
expect(comment.confidence_score).to eq(3750)
comment = create(:comment, :with_confidence_score, cached_votes_up: 750, cached_votes_total: 1000)
expect(comment.confidence_score).to eq(37500)
comment = create(:comment, :with_confidence_score, cached_votes_up: 10, cached_votes_total: 100)
expect(comment.confidence_score).to eq(-800)
end
describe 'actions which affect it' do
let(:comment) { create(:comment, :with_confidence_score) }
it "increases with like" do
previous = comment.confidence_score
5.times { comment.vote_by(voter: create(:user), vote: true) }
expect(previous).to be < comment.confidence_score
end
it "decreases with dislikes" do
comment.vote_by(voter: create(:user), vote: true)
previous = comment.confidence_score
3.times { comment.vote_by(voter: create(:user), vote: false) }
expect(previous).to be > comment.confidence_score
end
end
end
describe "cache" do
let(:comment) { create(:comment) }