Merge branch 'danibaena-master'

This commit is contained in:
Juanjo Bazán
2016-01-21 18:03:50 +01:00
4 changed files with 8 additions and 2 deletions

View File

@@ -17,7 +17,7 @@ module ScoreCalculator
end
def self.confidence_score(votes_total, votes_up)
return 0 unless votes_total > 0
return 1 unless votes_total > 0
votes_total = votes_total.to_f
votes_up = votes_up.to_f

View File

@@ -56,6 +56,9 @@ describe Comment do
comment = create(:comment, :with_confidence_score, cached_votes_up: 10, cached_votes_total: 100)
expect(comment.confidence_score).to eq(-800)
comment = create(:comment, :with_confidence_score, cached_votes_up: 0, cached_votes_total: 0)
expect(comment.confidence_score).to eq(1)
end
describe 'actions which affect it' do

View File

@@ -290,6 +290,9 @@ describe Debate do
debate = create(:debate, :with_confidence_score, cached_votes_up: 0, cached_votes_total: 100)
expect(debate.confidence_score).to eq(0)
debate = create(:debate, :with_confidence_score, cached_votes_up: 0, cached_votes_total: 0)
expect(debate.confidence_score).to eq(1)
debate = create(:debate, :with_confidence_score, cached_votes_up: 75, cached_votes_total: 100)
expect(debate.confidence_score).to eq(3750)

View File

@@ -293,7 +293,7 @@ describe Proposal do
expect(proposal.confidence_score).to eq(10000)
proposal = create(:proposal, :with_confidence_score, cached_votes_up: 0)
expect(proposal.confidence_score).to eq(0)
expect(proposal.confidence_score).to eq(1)
proposal = create(:proposal, :with_confidence_score, cached_votes_up: 75)
expect(proposal.confidence_score).to eq(7500)