phase002 complete

This commit is contained in:
2026-09-15 20:28:07 -06:00
parent 9793cd08bc
commit a3a65c24ed
28 changed files with 656 additions and 13 deletions
+22
View File
@@ -0,0 +1,22 @@
class Vehicle < ApplicationRecord
has_many :maintenance_schedules, dependent: :restrict_with_error
has_many :fuel_entries, dependent: :restrict_with_error
has_many :maintenance_entries, dependent: :restrict_with_error
before_validation :normalize_vin
validates :make, :model, :color, :vin, :licence_plate, presence: true
validates :vin, uniqueness: true
validates :licence_plate, uniqueness: { case_sensitive: false }
validates :year, presence: true,
numericality: { only_integer: true, greater_than_or_equal_to: 1980, less_than_or_equal_to: ->(_vehicle) { Date.current.year } }
validates :current_odometer, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :fuel_tank_size, presence: true, numericality: { greater_than: 0 }
validates :active, inclusion: { in: [ true, false ] }
private
def normalize_vin
self.vin = vin.to_s.strip.upcase if vin.present?
end
end