From 9218748c58d552432e7bd4a34383589eb17ac331 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Fri, 23 Nov 2007 01:48:53 -0800 Subject: [PATCH] Add MaxVideos and MaxGames RentablePolicies Signed-off-by: Ira W. Snyder --- app/controllers/purchase_controller.rb | 15 ++++++++++++++ app/models/customer.rb | 26 +++++++++++++++++++++++++ db/development.sqlite3 | Bin 17408 -> 19456 bytes 3 files changed, 41 insertions(+) diff --git a/app/controllers/purchase_controller.rb b/app/controllers/purchase_controller.rb index 704e38b..a3b61bb 100644 --- a/app/controllers/purchase_controller.rb +++ b/app/controllers/purchase_controller.rb @@ -58,6 +58,21 @@ class PurchaseController < ApplicationController return end + # Check Rentable Policies + @maxvideos = RentablePolicy.find_by_name("MaxVideos") + if @rentable.class == Video and @customer.checked_out_videos >= @maxvideos.value + flash[:error] = "#{@maxvideos.description} LIMIT REACHED" + redirect_to :action => :rent_begin + return + end + + @maxgames = RentablePolicy.find_by_name("MaxGames") + if @rentable.class == Game and @customer.checked_out_games >= @maxgames.value + flash[:error] = "#{@maxgames.description} LIMIT REACHED" + redirect_to :action => :rent_begin + return + end + # Check out the item checkout = Coitem.new checkout.customer = @customer diff --git a/app/models/customer.rb b/app/models/customer.rb index aba5044..e56eafe 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -7,6 +7,32 @@ class Customer < ActiveRecord::Base validates_presence_of :name, :email, :phone, :address validates_numericality_of :debt + def checked_out_videos + coitems = Coitem.find_all_by_customer_id(id) + video_count = 0 + + for item in coitems + if item.rentable.class == Video + video_count += 1 + end + end + + return video_count + end + + def checked_out_games + coitems = Coitem.find_all_by_customer_id(id) + game_count = 0 + + for item in coitems + if item.rentable.class == Game + game_count += 1 + end + end + + return game_count + end + protected def validate diff --git a/db/development.sqlite3 b/db/development.sqlite3 index f7ee02ebeb741262a73d76c165dd1a1ab5bec04b..8470ab98fe0cb2805103a9e796c661c079a64566 100644 GIT binary patch delta 622 zcmY+>KTK0m6bA6~=e@qCh1itf1FP^9_&}w$TAC2UP@NoLA{a*nN+4iMg2s_HVL+#1 z7Y1A$h$BrGMq^?eSR5T$Ok7+Tj3y-TUUJglnSM9t-t#5r*0#B}%Z*I;K3%BR*m1J$ zPyEwBzmP9`q(9|E_w}6|X-PA(*Q#$xF6&>Wpm>EdO!RbRv0R;9Su0l-%3*aWe6?H- zr(e9B-&m5l%4((hro!!`bg{q7jbcRq#9=+H^|!jySoG4l=#&aR=DXfcIvUVS(;LU7 z-}IF}&}*96c@zkOW_@bNEhHUWH7R;yX(1`i&8d;7$LO&hBOR;#F#Ao~TsqUo-BCmz zl}LZ+fo|(_oz#^4lFza$>+(cG{>$I_6W90|=h>%YI-~|IM-Qx!v(X;znG(pFT#TC> z+%+lgm;|>?j4_jsQIiLl5*RVL7&bW=GAVAE1UF5L(Bxv!2?FE#XH?H?^7g-WnqYOs(C6%pE|egYLi1RY#l`~-qSTR{+)S`MV6 zlR62di-U{Rt)t*91wn971XpX)kb+C^hUaT8X4 z&4{~480GkjFL;YbxQ27^1y9g~eXvQNJdBI8{?|?4l+f?9Ii0rAwPrM t^D=PiWyT