Add Purchase system
[cs356-p2-videostore.git] / app / models / purchase.rb
index 023f423..ff07e41 100644 (file)
@@ -1,4 +1,15 @@
 class Purchase < ActiveRecord::Base
   belongs_to :customer
-  belongs_to :purchaseable, :polymorphic => true
+
+  validates_presence_of :customer_id
+  validates_presence_of :date
+  validates_presence_of :price
+  validates_numericality_of :price
+
+  protected
+  def validate
+    errors.add(:price, "cannot be negative") if price < 0
+    errors.add(:price, "cannot be less than $0.01") if price < 0.01
+    errors.add(:customer_id, "does not exist in the database") if customer.nil?
+  end
 end