Files
car-tracker/app/models/maintenance_schedule.rb
bionickatana 87d2141ed0
CI / scan_ruby (push) Failing after 7s
CI / scan_js (push) Failing after 7s
CI / lint (push) Failing after 8s
Finished phase006
2026-09-16 16:37:03 -06:00

22 lines
873 B
Ruby

class MaintenanceSchedule < ApplicationRecord
belongs_to :vehicle
validates :maintenance_type, presence: true, uniqueness: { scope: :vehicle_id, case_sensitive: false }
validates :mileage_interval, presence: true, numericality: { only_integer: true, greater_than: 0 }
validates :time_interval, presence: true, numericality: { only_integer: true, greater_than: 0 }
validates :baseline_odometer, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :baseline_date, presence: true
validates :active, inclusion: { in: [ true, false ] }
validate :baseline_date_cannot_be_in_the_future
scope :active, -> { where(active: true) }
private
def baseline_date_cannot_be_in_the_future
return if baseline_date.blank? || baseline_date <= Date.current
errors.add(:baseline_date, "can't be in the future")
end
end