Makes comments increase the hot_score

This commit is contained in:
kikito
2015-09-04 14:04:45 +02:00
parent 2975c6a38d
commit 9bb63e9b32
3 changed files with 16 additions and 0 deletions

View File

@@ -24,6 +24,8 @@ class Comment < ActiveRecord::Base
scope :for_render, -> { with_hidden.includes(user: :organization) }
after_create :call_after_commented
def self.build(commentable, user, body, p_id=nil)
new commentable: commentable,
user_id: user.id,
@@ -87,4 +89,8 @@ class Comment < ActiveRecord::Base
!root?
end
def call_after_commented
self.commentable.try(:after_commented)
end
end

View File

@@ -104,6 +104,10 @@ class Debate < ActiveRecord::Base
update(ignored_flag_at: Time.now)
end
def after_commented
save # updates teh hot_score because there is a before_save
end
def calculate_hot_score
z = 1.96 # Normal distribution with a confidence of 0.95
time_unit = 1.0 * 12.hours

View File

@@ -229,6 +229,12 @@ describe Debate do
3.times { debate.register_vote(create(:user), false) }
expect(previous).to be > debate.hot_score
end
it "increases with comments" do
previous = debate.hot_score
Comment.create(user: create(:user), commentable: debate, body: 'foo')
expect(previous).to be < debate.hot_score
end
end
end