Makes votes increase/decrease hot score

Debates already call update_attibutes in debates (to update cached
counters), so there is no need to do an “after_voted”: the comment’s
before_save call takes care of it.
This commit is contained in:
kikito
2015-09-04 14:04:18 +02:00
parent 83ebbb14b1
commit 2975c6a38d

View File

@@ -184,35 +184,55 @@ describe Debate do
describe '#hot_score' do
let(:now) { Time.now }
it "gets bigger for newer debates" do
it "increases for newer debates" do
old = create(:debate, :with_hot_score, created_at: now - 1.day)
new = create(:debate, :with_hot_score, created_at: now)
expect(new.hot_score).to be > old.hot_score
end
it "gets bigger for debates with more comments" do
it "increases for debates with more comments" do
more_comments = create(:debate, :with_hot_score, created_at: now, comments_count: 10)
less_comments = create(:debate, :with_hot_score, created_at: now, comments_count: 1)
expect(more_comments.hot_score).to be > less_comments.hot_score
end
it "gets bigger for debates with more positive votes" do
it "increases for debates with more positive votes" do
more_likes = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 10, cached_votes_up: 5)
less_likes = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 10, cached_votes_up: 1)
expect(more_likes.hot_score).to be > less_likes.hot_score
end
it "gets bigger for debates with more confidence" do
it "increases for debates with more confidence" do
more_confidence = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 1000, cached_votes_up: 700)
less_confidence = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 10, cached_votes_up: 9)
expect(more_confidence.hot_score).to be > less_confidence.hot_score
end
it "decays older debates, even if they have more votes" do
it "decays in older debates, even if they have more votes" do
older_more_voted = create(:debate, :with_hot_score, created_at: now - 2.days, cached_votes_total: 1000, cached_votes_up: 900)
new_less_voted = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 10, cached_votes_up: 9)
expect(new_less_voted.hot_score).to be > older_more_voted.hot_score
end
describe 'actions which affect it' do
let(:debate) { create(:debate, :with_hot_score) }
it "increases with likes" do
previous = debate.hot_score
5.times { debate.register_vote(create(:user), true) }
expect(previous).to be < debate.hot_score
end
it "decreases with dislikes" do
debate.register_vote(create(:user), true)
previous = debate.hot_score
3.times { debate.register_vote(create(:user), false) }
expect(previous).to be > debate.hot_score
end
end
end
end