Makes comments increase the hot_score
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user