1 class BonusPolicy < ActiveRecord::Base
3 validates_presence_of :number
4 validates_presence_of :bonus_type
5 validates_presence_of :days
7 validates_numericality_of :number
8 validates_numericality_of :days
11 return "One #{bonus_type} free after #{number} #{bonus_type} rentals in the last #{days} days"
16 errors.add(:days, "must be at least 1") if days.nil? || days < 1
17 errors.add(:number, "must be at least 1") if number.nil? || number < 1
18 errors.add(:bonus_type, "must be either Video or Game") unless bonus_type == 'Video' or bonus_type == 'Game'