diff --git a/app/controllers/volunteers_controller.rb b/app/controllers/volunteers_controller.rb index 86689239..cc3b672d 100755 --- a/app/controllers/volunteers_controller.rb +++ b/app/controllers/volunteers_controller.rb @@ -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) diff --git a/app/views/volunteers/home.html.erb b/app/views/volunteers/home.html.erb index 7cff569e..25dab6b1 100755 --- a/app/views/volunteers/home.html.erb +++ b/app/views/volunteers/home.html.erb @@ -1,7 +1,7 @@ -<% if @sncs_count > 0 %> +<% if @total_shifts_needing_cov > 0 %>
- <%= @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 %>
<% end %> @@ -111,7 +111,7 @@

Shifts Needing Covering!

- <% if @sncs_pickups.length > 0 %> + <% if @shifts_needing_cov.length > 0 %> @@ -123,17 +123,17 @@ <% 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? } %>
- <% shift.logs.each{ |pickup| %> - <% next if pickup.donor.nil? or pickup.recipients.empty? %> - <%= link_to pickup.donor.name, pickup.donor %> -> <% 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 %> -> <% log.recipients.each do |recip| %> <%=link_to recip.name, recip %> <% end %> + <% unless log.food_types.empty? %>
- (<%= pickup.food_types.collect{ |ft| ft.name }.join(",") %>) + (<%= log.food_types.collect{ |type| type.name }.join(",") %>) <% end %>
<% } %> diff --git a/spec/features/shifts_needing_coverage_spec.rb b/spec/features/shifts_needing_coverage_spec.rb new file mode 100644 index 00000000..7fd20b83 --- /dev/null +++ b/spec/features/shifts_needing_coverage_spec.rb @@ -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