2
0

Add coverage for TermsOfService scopes/validations (#35204)

This commit is contained in:
Matt Jankowski
2025-06-30 06:28:14 -04:00
committed by GitHub
parent 8782e860b6
commit 964916c71b
2 changed files with 84 additions and 3 deletions

View File

@@ -15,9 +15,9 @@
#
class TermsOfService < ApplicationRecord
scope :published, -> { where.not(published_at: nil).order(Arel.sql('coalesce(effective_date, published_at) DESC')) }
scope :live, -> { published.where('effective_date IS NULL OR effective_date < now()').limit(1) }
scope :upcoming, -> { published.reorder(effective_date: :asc).where('effective_date IS NOT NULL AND effective_date > now()').limit(1) }
scope :draft, -> { where(published_at: nil).order(id: :desc).limit(1) }
scope :live, -> { published.where('effective_date IS NULL OR effective_date < now()') }
scope :upcoming, -> { published.reorder(effective_date: :asc).where('effective_date IS NOT NULL AND effective_date > now()') }
scope :draft, -> { where(published_at: nil).order(id: :desc) }
validates :text, presence: true
validates :changelog, :effective_date, presence: true, if: -> { published? }