Add Income tracking to the Purchase System
[cs356-p2-videostore.git] / app / models / purchase.rb
1 class Purchase < ActiveRecord::Base
2   belongs_to :customer
3
4   validates_presence_of :customer_id
5   validates_presence_of :date
6   validates_presence_of :price
7   validates_numericality_of :price
8
9   def title
10     if type == MerchandisePurchase
11       return merchandise.title
12     elsif type == RentablePurchase
13       return rentable.title
14     else
15       return 'Late Fees'
16     end
17   end
18
19   protected
20   def validate
21     errors.add(:price, "cannot be negative") if price < 0
22     errors.add(:price, "cannot be less than $0.01") if price < 0.01
23     errors.add(:customer_id, "does not exist in the database") if customer.nil?
24   end
25 end