A platform for community discussion. Free, open, simple.
FIX: prevents topic hot scope error on future topics (#28545)
Joffrey JAFFEUXf7990ec8f6b4
diff --git a/app/models/topic_hot_score.rb b/app/models/topic_hot_score.rbindex a2f8c6d9b85..570f163cabd 100644--- a/app/models/topic_hot_score.rb+++ b/app/models/topic_hot_score.rb@@ -141,7 +141,7 @@ class TopicHotScore < ActiveRecord::BaseFROM topicsWHERE topics.id IN (SELECT topic_id FROM topic_ids- ) AND ths.topic_id = topics.id+ ) AND ths.topic_id = topics.id AND topics.created_at <= :nowSQLDB.exec(sql, args)diff --git a/spec/models/topic_hot_scores_spec.rb b/spec/models/topic_hot_scores_spec.rbindex 89e61356fa2..e2882fc6cd7 100644--- a/spec/models/topic_hot_scores_spec.rb+++ b/spec/models/topic_hot_scores_spec.rb@@ -111,5 +111,18 @@ RSpec.describe TopicHotScore doexpect(TopicHotScore.find_by(topic_id: topic1.id).score).to be_within(0.0001).of(0.0005)expect(TopicHotScore.find_by(topic_id: topic2.id).score).to be_within(0.001).of(0.001)end++ it "ignores topics in the future" do+ freeze_time++ topic1 = Fabricate(:topic, like_count: 3, created_at: 2.days.from_now)+ post1 = Fabricate(:post, topic: topic1, created_at: 1.minute.ago)+ PostActionCreator.like(user, post1)+ TopicHotScore.create!(topic_id: topic1.id, score: 0.0, recent_likes: 0, recent_posters: 0)++ expect { TopicHotScore.update_scores }.not_to change {+ TopicHotScore.where(topic_id: topic1.id).pluck(:recent_likes)+ }+ endendend