Permalink
Browse files

limit to 1 checkout per day

  • Loading branch information...
1 parent a3f7ad6 commit 39bce1e77c3fc577b174542c2b2fedbc44dae798 @jdxcode committed Mar 8, 2012
@@ -1,8 +1,11 @@
class CheckoutsController < ApplicationController
before_filter :authenticate_user!
- def new
- @checkout = Checkout.new
+ def show
+ unless current_user.todays_checkout
+ @checkout = Checkout.new
+ render :new
+ end
end
def create
View
@@ -1,9 +1,15 @@
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
+ has_many :checkouts
+
attr_accessible :email, :password, :remember_me
def to_s
email
end
+
+ def todays_checkout
+ checkouts.where('DATE(created_at) = DATE(?)', Time.now).first
+ end
end
@@ -0,0 +1 @@
+You have already checked out today.
@@ -17,7 +17,7 @@
%a.brand{ href: root_path} MirrorApp
.nav-collapse
%ul.nav
- %li= link_to "Check out", new_checkout_path
+ %li= link_to "Check out", checkout_path if user_signed_in?
- if user_signed_in?
%ul.nav.pull-right
%li.dropdown
@@ -6,5 +6,6 @@
end
Then /^I should have checked out$/ do
- pending
+ click_link 'Check out'
+ page.should have_content 'You have already checked out today'
end

0 comments on commit 39bce1e

Please sign in to comment.