Fix intermittent failure of TOS model spec from effective date collision (#35244)

This commit is contained in:
Matt Jankowski 2025-07-03 12:28:47 -04:00 committed by GitHub
parent 2af17adc34
commit e8d2432e6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,22 +44,24 @@ RSpec.describe TermsOfService do
end
describe '.live' do
let!(:not_effective) { Fabricate :terms_of_service }
# The `pre_effective_date` record captures a period before the value was tracked
# The update in the `before` block creates an invalid (but historically plausible) record
let!(:pre_effective_date) { travel_to(10.days.ago) { Fabricate :terms_of_service, effective_date: Time.zone.today } }
let!(:effective_past) { travel_to(3.days.ago) { Fabricate :terms_of_service, effective_date: Time.zone.today } }
let!(:effective_future) { Fabricate :terms_of_service, effective_date: 3.days.from_now }
before { not_effective.update_attribute(:effective_date, nil) }
before { pre_effective_date.update_attribute(:effective_date, nil) }
it 'returns records without effective or with past effective' do
expect(described_class.live)
.to include(not_effective)
.to include(pre_effective_date)
.and include(effective_past)
.and not_include(effective_future)
end
end
describe '.upcoming' do
let!(:unpublished) { Fabricate :terms_of_service, published_at: nil }
let!(:unpublished) { Fabricate :terms_of_service, published_at: nil, effective_date: 10.days.from_now }
let!(:effective_past) { travel_to(3.days.ago) { Fabricate :terms_of_service, effective_date: Time.zone.today } }
let!(:effective_future_near) { Fabricate :terms_of_service, effective_date: 3.days.from_now }
let!(:effective_future_far) { Fabricate :terms_of_service, effective_date: 5.days.from_now }