Fix missing terms of services link (#35115)

This commit is contained in:
David Roetzel 2025-06-21 10:59:47 +02:00 committed by GitHub
commit adf812efb3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 60 additions and 3 deletions

View file

@ -24,4 +24,55 @@ RSpec.describe TermsOfService do
expect(subject.pluck(:id)).to match_array(user_before.id)
end
end
describe '::current' do
context 'when no terms exist' do
it 'returns nil' do
expect(described_class.current).to be_nil
end
end
context 'when only unpublished terms exist' do
before do
yesterday = Date.yesterday
travel_to yesterday do
Fabricate(:terms_of_service, published_at: nil, effective_date: yesterday)
end
Fabricate(:terms_of_service, published_at: nil, effective_date: Date.tomorrow)
end
it 'returns nil' do
expect(described_class.current).to be_nil
end
end
context 'when both effective and future terms exist' do
let!(:effective_terms) do
yesterday = Date.yesterday
travel_to yesterday do
Fabricate(:terms_of_service, effective_date: yesterday)
end
end
before do
Fabricate(:terms_of_service, effective_date: Date.tomorrow)
end
it 'returns the effective terms' do
expect(described_class.current).to eq effective_terms
end
end
context 'when only future terms exist' do
let!(:upcoming_terms) { Fabricate(:terms_of_service, effective_date: Date.tomorrow) }
before do
Fabricate(:terms_of_service, effective_date: 10.days.since)
end
it 'returns the terms that are upcoming next' do
expect(described_class.current).to eq upcoming_terms
end
end
end
end