From 062ed9c2d17f5e2d36f8469fb593470de9ac5493 Mon Sep 17 00:00:00 2001 From: Jason Denney Date: Wed, 12 Mar 2014 21:52:37 -0400 Subject: [PATCH] Added tests for user checkin/checkout on index --- app/models/user.rb | 17 ++++++++++------- spec/features/site/index_spec.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 spec/features/site/index_spec.rb diff --git a/app/models/user.rb b/app/models/user.rb index 3cc2c4b..59a468f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -114,28 +114,31 @@ class User < ActiveRecord::Base end def checked_in? - log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN") - checked = logs.where( log_action_id: log_action.id). + #default CHECKIN log action is id, yea yea should be a constant + 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 = end_date") !checked.empty? end 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 logs.create( logger_id: self.id, logger_type: self.class.to_s, start_date: time, end_date: time, - log_action_id: log_action.id, - log_action_type: log_action.class.to_s) + log_action_id: log_action_id, + log_action_type: ::ActsAsLoggable::UserAction.to_s) save end def checkout - log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN") - checked = logs.where( log_action_id: log_action.id). + #default CHECKIN log action is id, yea yea should be a constant + 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 = end_date").first checked.end_date = Time.now diff --git a/spec/features/site/index_spec.rb b/spec/features/site/index_spec.rb new file mode 100644 index 0000000..85cec75 --- /dev/null +++ b/spec/features/site/index_spec.rb @@ -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