diff --git a/app/models/topic_hot_score.rb b/app/models/topic_hot_score.rb index 570f163cabd..a58fb6d8837 100644 --- a/app/models/topic_hot_score.rb +++ b/app/models/topic_hot_score.rb @@ -145,6 +145,8 @@ class TopicHotScore < ActiveRecord::Base SQL DB.exec(sql, args) + + DiscourseEvent.trigger(:topic_hot_scores_updated) end end diff --git a/spec/models/topic_hot_scores_spec.rb b/spec/models/topic_hot_scores_spec.rb index e2882fc6cd7..77759b53188 100644 --- a/spec/models/topic_hot_scores_spec.rb +++ b/spec/models/topic_hot_scores_spec.rb @@ -124,5 +124,20 @@ RSpec.describe TopicHotScore do TopicHotScore.where(topic_id: topic1.id).pluck(:recent_likes) } end + + it "triggers an event after updating" do + triggered = false + blk = Proc.new { triggered = true } + + begin + DiscourseEvent.on(:topic_hot_scores_updated, &blk) + + TopicHotScore.update_scores + + expect(triggered).to eq(true) + ensure + DiscourseEvent.off(:topic_hot_scores_updated, &blk) + end + end end end