Skip to content

Commit

Permalink
Add feature test for viewing shifts needing cov.
Browse files Browse the repository at this point in the history
Includes test for not seeing irrelevant shifts.
Change shift count variable name for readability.
  • Loading branch information
tmikeschu committed Apr 2, 2017
1 parent 5eb6667 commit 1b3b0f7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/controllers/volunteers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ def home

#Upcoming pickup list
@upcoming_pickups = Shift.build_shifts(Log.upcoming_for(current_volunteer.id))
@sncs_pickups = Shift.build_shifts(Log.needing_coverage(current_volunteer.region_ids, 7, 10))
@sncs_count = Log.needing_coverage(current_volunteer.region_ids, 7).length
@shifts_needing_cov = Shift.build_shifts(Log.needing_coverage(current_volunteer.region_ids, 7, 10))
@total_shifts_needing_cov= Log.needing_coverage(current_volunteer.region_ids, 7).length

#To Do Pickup Reports
@to_do_reports = Log.picked_up_by(current_volunteer.id, false)
Expand Down
20 changes: 10 additions & 10 deletions app/views/volunteers/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% if @sncs_count > 0 %>
<% if @total_shifts_needing_cov > 0 %>
<div class="alert fade in alert-danger" onclick="window.location='<%= open_logs_path %>';" style="cursor:pointer;">
<i class="fa fa-exclamation-triangle"></i>
<%= @sncs_count %> Shifts Need Covering Soon: <%= link_to "Pick one up here.", open_logs_path %>
<%= @total_shifts_needing_cov %> Shifts Need Covering Soon: <%= link_to "Pick one up here.", open_logs_path %>
</div>
<% end %>
Expand Down Expand Up @@ -111,7 +111,7 @@
<div class="row bordered-bottom">
<div class="col-sm-6">
<h2>Shifts Needing Covering!</h2>
<% if @sncs_pickups.length > 0 %>
<% if @shifts_needing_cov.length > 0 %>
<table class="table table-striped">
<thead>
<tr>
Expand All @@ -123,17 +123,17 @@
</thead>
<tbody>
<% n = 0
@sncs_pickups.each do |shift|
next if shift.logs.all? {|x| x.donor.nil? or x.recipients.empty? }
@shifts_needing_cov.each do |shift|
next if shift.logs.all? {|log| log.donor.nil? or log.recipients.empty? }
%>
<tr class="bordered">
<td>
<% shift.logs.each{ |pickup| %>
<% next if pickup.donor.nil? or pickup.recipients.empty? %>
<%= link_to pickup.donor.name, pickup.donor %> -&gt; <% pickup.recipients.each do |recip| %> <%=link_to recip.name, recip %> <% end %>
<% unless pickup.food_types.empty? %>
<% shift.logs.each{ |log| %>
<% next if log.donor.nil? or log.recipients.empty? %>
<%= link_to log.donor.name, log.donor %> -&gt; <% log.recipients.each do |recip| %> <%=link_to recip.name, recip %> <% end %>
<% unless log.food_types.empty? %>
<br />
<em>(<%= pickup.food_types.collect{ |ft| ft.name }.join(",") %>)</em>
<em>(<%= log.food_types.collect{ |type| type.name }.join(",") %>)</em>
<% end %>
<br />
<% } %>
Expand Down
37 changes: 37 additions & 0 deletions spec/features/shifts_needing_coverage_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'rails_helper'

RSpec.describe 'Shifts needing coverage' do
let(:region) { create(:region) }
let(:volunteer) { create(:volunteer, :not_waived, regions: [region], assigned: true) }
let!(:log) { create(:log, region_id: volunteer.region_ids[0], when: Time.zone.today + 1.day) }

feature 'When a volunteer visits the homepage' do
before(:each) do
login volunteer
allow_any_instance_of(ApplicationController).to receive(:current_volunteer).and_return(volunteer)
allow(volunteer).to receive(:waiver_signed?).and_return(true)
end

it 'they see the shifts in their region that need covering' do
visit root_path

within page.find('h2', text: 'Shifts Needing Covering').find('+table') do
expect(page).to have_link(log.donor.name, href: location_path(log.donor))
expect(page).to have_button('Take')
log.food_types.each do |type|
expect(page).to have_content(type.name)
end
end
end

it 'and they dont see the shifts out of their region that need covering' do
other_region_log = create(:log, when: Time.zone.today + 2.days)

visit root_path

within page.find('h2', text: 'Shifts Needing Covering').find('+table') do
expect(page).to_not have_link(other_region_log.donor.name, href: location_path(other_region_log.donor))
end
end
end
end

0 comments on commit 1b3b0f7

Please sign in to comment.