Skip to content

Commit

Permalink
Add weekly digest messsages for no addditional notes and no pending v…
Browse files Browse the repository at this point in the history
…olunteers
  • Loading branch information
colefortner committed Sep 9, 2021
1 parent 0fc3fe9 commit c7cfcbe
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
12 changes: 12 additions & 0 deletions app/mailers/supervisor_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ def account_setup(supervisor)
def weekly_digest(supervisor)
@supervisor = supervisor
@casa_organization = supervisor.casa_org
@inactive_messages = inactive_messages(supervisor)
@show_notes = @inactive_messages.none?
mail(to: @supervisor.email, subject: "Weekly summary of volunteers' activities for the week of #{Date.today - 7.days}")
end

def inactive_messages(supervisor)
supervisor.volunteers.map do |volunteer|
inactive_cases = CaseAssignment.inactive_this_week(volunteer.id)
inactive_cases.map do |case_assignment|
inactive_case_number = case_assignment.casa_case.case_number
"#{volunteer.display_name} Case #{inactive_case_number} marked inactive this week."
end
end.flatten
end
end
3 changes: 1 addition & 2 deletions app/models/case_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class CaseAssignment < ApplicationRecord
scope :active, -> { where(active: true) }

def self.inactive_this_week(volunteer_id)
this_week = Date.today - 7.days..Date.today
where(updated_at: this_week).where(active: false).where(volunteer_id: volunteer_id)
where("updated_at > ?",1.week.ago).where(active: false).where(volunteer_id: volunteer_id)
end

private
Expand Down
30 changes: 20 additions & 10 deletions app/views/supervisor_mailer/weekly_digest.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,32 @@
</td>
</tr>


<tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<% @supervisor.volunteers.each do |volunteer| %>
<% inactive_cases = CaseAssignment.inactive_this_week(volunteer.id) %>
<% inactive_cases.each do |case_assignment| %>
<td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 16px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
<% inactive_case_number = case_assignment.casa_case.case_number %>
<%= "#{volunteer.display_name} Case #{inactive_case_number} marked inactive this week." %>
<br>
<% @inactive_messages.each do |message|%>
<td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 16px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
<%= message %>
<br>
</td>
<% end %>
</tr>

<tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
<% if @show_notes %>
There are no additional notes.
<% end %>
</td>
</tr>
<% end %>
<% end %>

<tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
<b>Pending Volunteers:</b>
<br>
<% if @supervisor.pending_volunteers.empty? %>
<br>
There are no pending volunteers.
<% end %>
</td>
</tr>

Expand All @@ -124,6 +133,7 @@
<td>
<button> <%= link_to "Re-invite", resend_invitation_volunteer_url(volunteer) %></button>
</td>
</tr>
</tr>
<% end %>

</table>
18 changes: 18 additions & 0 deletions spec/mailers/supervisor_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@

expect(mail.body.encoded).to_not match(volunteer2.display_name.to_s)
end

it "does not display 'There are no pending volunteers' message when there are pending volunteers" do
expect(mail.body.encoded).to_not match("There are no pending volunteers.")
end
end

it "displays no pending volunteers message when there are no pending volunteers" do
expect(mail.body.encoded).to match("There are no pending volunteers.")
end

it "does not display 'There are no additional notes' message when there are additional notes" do
# this_week = Date.today - 7.days..Date.today
create(:case_assignment, casa_case: casa_case, volunteer: volunteer, active: false, updated_at: Date.today - 8.days)
expect(mail.body.encoded).to_not match("There are no additional notes.")
end

it "displays no additional notes messsage when there are no additional notes" do
expect(mail.body.encoded).to match("There are no additional notes.")
end
end

Expand Down

0 comments on commit c7cfcbe

Please sign in to comment.