mirror of
				https://github.com/fspc/BikeShed-1.git
				synced 2025-10-31 17:05:36 -04:00 
			
		
		
		
	Added tests for user checkin/checkout on index
This commit is contained in:
		
							parent
							
								
									124ce5901d
								
							
						
					
					
						commit
						062ed9c2d1
					
				| @ -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 | ||||||
|  | |||||||
							
								
								
									
										32
									
								
								spec/features/site/index_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								spec/features/site/index_spec.rb
									
									
									
									
									
										Normal 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 | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user