Lots of stuff, I got too tired to keep perfect revision history
[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 self.class == MerchandisePurchase
11       return merchandise.title
12     elsif self.class == RentablePurchase
13       return rentable.title
14     elsif self.class == BonusPurchase
15       return rentable.title
16     else
17       return 'Late Fees'
18     end
19   end
20
21   protected
22   def validate
23     errors.add(:price, "cannot be negative") if price < 0
24     # Need to leave this out for bonuses
25     #errors.add(:price, "cannot be less than $0.01") if price < 0.01
26     errors.add(:customer_id, "does not exist in the database") if customer.nil?
27   end
28 end