DEV: Trigger an event after updating topic hot scores (#29261)

This commit is contained in:
Roman Rizzi 2024-10-18 11:08:48 -03:00 committed by GitHub
parent e95edd079b
commit f227f66b11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -145,6 +145,8 @@ class TopicHotScore < ActiveRecord::Base
SQL SQL
DB.exec(sql, args) DB.exec(sql, args)
DiscourseEvent.trigger(:topic_hot_scores_updated)
end end
end end

View File

@ -124,5 +124,20 @@ RSpec.describe TopicHotScore do
TopicHotScore.where(topic_id: topic1.id).pluck(:recent_likes) TopicHotScore.where(topic_id: topic1.id).pluck(:recent_likes)
} }
end 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
end end