DEV: Fix flaky request tracker system spec (#29136)

`Date.today` relies on the system's timezone instead of
`Rails.configuration.time_zone`. This can cause tests to fail when we
assert against the date of a record. Just use `Time.zone.today` instead
so that we always follow `Rails.configuration.time_zone`.
This commit is contained in:
Alan Guo Xiang Tan 2024-10-09 07:53:08 +08:00 committed by GitHub
parent ed6c9d1545
commit 27c34915ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 1 deletions

View File

@ -11,7 +11,8 @@ class TopicViewItem < ActiveRecord::Base
def self.add(topic_id, ip, user_id = nil, at = nil, skip_redis = false)
# Only store a view once per day per thing per (user || ip)
at ||= Date.today
at ||= Time.zone.today
redis_key = +"view:#{topic_id}:#{at}"
if user_id
redis_key << ":user-#{user_id}"