1
0
mirror of https://github.com/fspc/BikeShed-1.git synced 2025-02-28 16:53:23 -05:00

Added tests for user checkin/checkout on index

This commit is contained in:
Jason Denney 2014-03-12 21:52:37 -04:00
parent 124ce5901d
commit 062ed9c2d1
2 changed files with 42 additions and 7 deletions

View File

@ -114,28 +114,31 @@ class User < ActiveRecord::Base
end end
def checked_in? def checked_in?
log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN") #default CHECKIN log action is id, yea yea should be a constant
checked = logs.where( log_action_id: log_action.id). log_action_id = 4
checked = logs.where( log_action_id: log_action_id).
where("start_date >= ?", Time.zone.now.beginning_of_day). where("start_date >= ?", Time.zone.now.beginning_of_day).
where("start_date = end_date") where("start_date = end_date")
!checked.empty? !checked.empty?
end end
def checkin def checkin
log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN") #default CHECKIN log action is id, yea yea should be a constant
log_action_id = 4
time = Time.now time = Time.now
logs.create( logger_id: self.id, logs.create( logger_id: self.id,
logger_type: self.class.to_s, logger_type: self.class.to_s,
start_date: time, start_date: time,
end_date: time, end_date: time,
log_action_id: log_action.id, log_action_id: log_action_id,
log_action_type: log_action.class.to_s) log_action_type: ::ActsAsLoggable::UserAction.to_s)
save save
end end
def checkout def checkout
log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN") #default CHECKIN log action is id, yea yea should be a constant
checked = logs.where( log_action_id: log_action.id). log_action_id = 4
checked = logs.where( log_action_id: log_action_id).
where("start_date >= ?", Time.zone.now.beginning_of_day). where("start_date >= ?", Time.zone.now.beginning_of_day).
where("start_date = end_date").first where("start_date = end_date").first
checked.end_date = Time.now checked.end_date = Time.now

View File

@ -0,0 +1,32 @@
require 'spec_helper'
describe "Index Page" do
before(:each) do
@user = FactoryGirl.create(:bike_admin)
visit root_path
fill_in "user_username", with: @user.username
fill_in "user_password", with: @user.password
end
it 'should have a link to check in' do
page.should have_button 'CHECK IN'
end
it 'should have a link to check out' do
page.should have_button 'CHECK OUT'
end
it 'clicking check in should check in a user' do
expect{click_button 'CHECK IN'}.
to change{@user.checked_in?}.
from(false).to(true)
end
it 'clicking check out should check out a user' do
@user.checkin
expect{click_button 'CHECK OUT'}.
to change{@user.checked_in?}.
from(true).to(false)
end
end