X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=app%2Fmodels%2Fpurchase.rb;h=ff07e41c2916691cb06073e760e49972ce5c1dca;hb=f96a0f6949f29078cd2c5e3c81d3ac48ac710fbe;hp=e688f99b8de4e7e46efe16f0afa76f108e032227;hpb=51e5c301fa78679232f16b450632fc890c02c4f2;p=cs356-p2-videostore.git diff --git a/app/models/purchase.rb b/app/models/purchase.rb index e688f99..ff07e41 100644 --- a/app/models/purchase.rb +++ b/app/models/purchase.rb @@ -1,2 +1,15 @@ class Purchase < ActiveRecord::Base + belongs_to :customer + + 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