Files
bionickatana 0826d267f2
CI / scan_ruby (push) Failing after 1m5s
CI / scan_js (push) Failing after 6s
CI / lint (push) Failing after 1m29s
Finished phase005
2026-09-16 15:34:50 -06:00

27 lines
912 B
Ruby

class FuelEntry < ApplicationRecord
belongs_to :vehicle
belongs_to :updated_by_user, class_name: "User"
validates :odometer, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :gallons_pumped, presence: true, numericality: { greater_than: 0 }
validates :price_paid, presence: true, numericality: { greater_than: 0 }
validates :date, presence: true
validate :date_cannot_be_in_the_future
validate :odometer_cannot_be_less_than_vehicle_current_odometer
private
def date_cannot_be_in_the_future
return if date.blank? || date <= Date.current
errors.add(:date, "can't be in the future")
end
def odometer_cannot_be_less_than_vehicle_current_odometer
return if vehicle.blank? || odometer.blank?
return if odometer >= vehicle.current_odometer
errors.add(:odometer, "cannot be less than the vehicle's current odometer")
end
end