From 66f1feef02dd7957cbcde92dd9bdcb319975328b Mon Sep 17 00:00:00 2001 From: Nidhi Sarvaiya Date: Wed, 13 Sep 2023 20:44:13 -0400 Subject: [PATCH 1/6] Implemented feature to send reimbursement reminder email to supervisor --- app/controllers/case_contacts_controller.rb | 8 ++++++++ app/mailers/supervisor_mailer.rb | 9 +++++++++ .../reimbursement_request_reminder.html.erb | 15 +++++++++++++++ .../previews/supervisor_mailer_preview.rb | 7 +++++++ .../previews/supervisor_mailer_preview_spec.rb | 17 +++++++++++++++++ spec/mailers/supervisor_mailer_spec.rb | 12 ++++++++++++ 6 files changed, 68 insertions(+) create mode 100644 app/views/supervisor_mailer/reimbursement_request_reminder.html.erb diff --git a/app/controllers/case_contacts_controller.rb b/app/controllers/case_contacts_controller.rb index 27386484bd..b78871593d 100644 --- a/app/controllers/case_contacts_controller.rb +++ b/app/controllers/case_contacts_controller.rb @@ -108,6 +108,9 @@ def update if @case_contact.valid? created_at = @case_contact.created_at.strftime("%-I:%-M %p on %m-%e-%Y") flash[:notice] = "Case contact created at #{created_at}, was successfully updated." + if @case_contact.want_driving_reimbursement_changed? && @case_contact.want_driving_reimbursement? && !current_user.supervisor.blank? + SupervisorMailer.reimbursement_request_reminder(current_user, current_user.supervisor).deliver + end redirect_to casa_case_path(@case_contact.casa_case) else render :edit @@ -169,6 +172,11 @@ def create_case_contact_for_every_selected_casa_case(selected_cases) end case_contact = @case_contact.dup + + if case_contact.want_driving_reimbursement? && !current_user.supervisor.blank? + SupervisorMailer.reimbursement_request_reminder(current_user, current_user.supervisor).deliver + end + case_contact.casa_case = casa_case if @selected_cases.count == 1 && case_contact.valid? if current_role == "Volunteer" diff --git a/app/mailers/supervisor_mailer.rb b/app/mailers/supervisor_mailer.rb index e6e642065e..fc0216e837 100644 --- a/app/mailers/supervisor_mailer.rb +++ b/app/mailers/supervisor_mailer.rb @@ -19,4 +19,13 @@ def weekly_digest(supervisor) subject: "Weekly summary of volunteers' activities for the week of #{Date.today - 7.days}" ) end + + def reimbursement_request_reminder(volunteer, supervisor) + @volunteer = volunteer + @casa_organization = volunteer.casa_org + @supervisor = supervisor + if supervisor.receive_reimbursement_email + mail(to: @supervisor.email, subject: "New reimbursement request from #{@volunteer.display_name}") + end + end end diff --git a/app/views/supervisor_mailer/reimbursement_request_reminder.html.erb b/app/views/supervisor_mailer/reimbursement_request_reminder.html.erb new file mode 100644 index 0000000000..7ec0044c1b --- /dev/null +++ b/app/views/supervisor_mailer/reimbursement_request_reminder.html.erb @@ -0,0 +1,15 @@ + + + + + + + + + +
+ Hello <%= @supervisor.display_name %>, +
+ <%= @volunteer.display_name %> has submitted a reimbursement request, please follow up on the reimbursements page + " target="_blank">this link to view reimbursement requests. +
diff --git a/lib/mailers/previews/supervisor_mailer_preview.rb b/lib/mailers/previews/supervisor_mailer_preview.rb index dbf56185af..abf031144e 100644 --- a/lib/mailers/previews/supervisor_mailer_preview.rb +++ b/lib/mailers/previews/supervisor_mailer_preview.rb @@ -38,6 +38,13 @@ def weekly_digest SupervisorMailer.weekly_digest(supervisor) end end + + def reimbursement_request_reminder + volunteer = params.has_key?(:volunteer_id) ? Volunteer.find_by(id: params[:volunteer_id]) : Volunteer.last + supervisor = params.has_key?(:supervisor_id) ? Supervisor.find_by(id: params[:supervisor_id]) : Supervisor.last + supervisor.receive_reimbursement_email = true + SupervisorMailer.reimbursement_request_reminder(volunteer, supervisor) + end end # :nocov: diff --git a/spec/mailers/previews/supervisor_mailer_preview_spec.rb b/spec/mailers/previews/supervisor_mailer_preview_spec.rb index 2da8642c1d..f6e0d57e61 100644 --- a/spec/mailers/previews/supervisor_mailer_preview_spec.rb +++ b/spec/mailers/previews/supervisor_mailer_preview_spec.rb @@ -3,6 +3,7 @@ RSpec.describe SupervisorMailerPreview do let!(:supervisor) { create(:supervisor) } + let!(:volunteer) { create(:volunteer) } describe "#account_setup" do context "When no ID is passed" do @@ -49,4 +50,20 @@ xit { expect(email.to).to eq ["missing_supervisor@example.com"] } end end + + describe "#reimbursement_request_reminder" do + context "When no ID is passed" do + let(:preview) { described_class.new } + let(:email) { preview.reimbursement_request_reminder } + + it { expect(email.to).to eq [supervisor.email] } + end + + context "When passed ID is valid" do + let(:preview) { described_class.new(volunteer_id: volunteer.id, supervisor_id: supervisor.id) } + let(:email) { preview.reimbursement_request_reminder } + + it { expect(email.to).to eq [supervisor.email] } + end + end end diff --git a/spec/mailers/supervisor_mailer_spec.rb b/spec/mailers/supervisor_mailer_spec.rb index 56c310dd26..e0229acf75 100644 --- a/spec/mailers/supervisor_mailer_spec.rb +++ b/spec/mailers/supervisor_mailer_spec.rb @@ -116,4 +116,16 @@ expect(email_body).to include("This invitation will expire on #{expiration_date} (two weeks).") end end + + describe ".reimbursement_request_reminder" do + let(:supervisor) { create(:supervisor, receive_reimbursement_email: true) } + let(:volunteer) { create(:volunteer) } + let(:casa_organization) { volunteer.casa_org } + + let(:mail) { SupervisorMailer.reimbursement_request_reminder(volunteer, supervisor) } + + it "sends email reminder" do + expect(mail.body.encoded).to match("#{volunteer.display_name} has submitted a reimbursement request") + end + end end From 6a456985e8a6ae126a42fc1fe63703242e7cbed1 Mon Sep 17 00:00:00 2001 From: Nidhi Sarvaiya Date: Wed, 13 Sep 2023 22:25:11 -0400 Subject: [PATCH 2/6] Fixed code climate issue and updated method name --- app/controllers/case_contacts_controller.rb | 14 ++++++++------ app/mailers/supervisor_mailer.rb | 2 +- ...ml.erb => reimbursement_request_email.html.erb} | 2 +- lib/mailers/previews/supervisor_mailer_preview.rb | 4 ++-- .../previews/supervisor_mailer_preview_spec.rb | 6 +++--- spec/mailers/supervisor_mailer_spec.rb | 4 ++-- 6 files changed, 17 insertions(+), 15 deletions(-) rename app/views/supervisor_mailer/{reimbursement_request_reminder.html.erb => reimbursement_request_email.html.erb} (91%) diff --git a/app/controllers/case_contacts_controller.rb b/app/controllers/case_contacts_controller.rb index b78871593d..ec74e24c06 100644 --- a/app/controllers/case_contacts_controller.rb +++ b/app/controllers/case_contacts_controller.rb @@ -108,9 +108,7 @@ def update if @case_contact.valid? created_at = @case_contact.created_at.strftime("%-I:%-M %p on %m-%e-%Y") flash[:notice] = "Case contact created at #{created_at}, was successfully updated." - if @case_contact.want_driving_reimbursement_changed? && @case_contact.want_driving_reimbursement? && !current_user.supervisor.blank? - SupervisorMailer.reimbursement_request_reminder(current_user, current_user.supervisor).deliver - end + send_reimbursement_email(@case_contact) redirect_to casa_case_path(@case_contact.casa_case) else render :edit @@ -173,9 +171,7 @@ def create_case_contact_for_every_selected_casa_case(selected_cases) case_contact = @case_contact.dup - if case_contact.want_driving_reimbursement? && !current_user.supervisor.blank? - SupervisorMailer.reimbursement_request_reminder(current_user, current_user.supervisor).deliver - end + send_reimbursement_email(case_contact) case_contact.casa_case = casa_case if @selected_cases.count == 1 && case_contact.valid? @@ -189,6 +185,12 @@ def create_case_contact_for_every_selected_casa_case(selected_cases) end end + def send_reimbursement_email(case_contact) + if case_contact.want_driving_reimbursement_changed? && case_contact.want_driving_reimbursement? && !current_user.supervisor.blank? + SupervisorMailer.reimbursement_request_email(current_user, current_user.supervisor).deliver + end + end + def update_volunteer_address(volunteer = current_user) content = create_case_contact_params.dig(:casa_case_attributes, :volunteers_attributes, "0", :address_attributes, :content) return if content.blank? diff --git a/app/mailers/supervisor_mailer.rb b/app/mailers/supervisor_mailer.rb index fc0216e837..c65caaf20d 100644 --- a/app/mailers/supervisor_mailer.rb +++ b/app/mailers/supervisor_mailer.rb @@ -20,7 +20,7 @@ def weekly_digest(supervisor) ) end - def reimbursement_request_reminder(volunteer, supervisor) + def reimbursement_request_email(volunteer, supervisor) @volunteer = volunteer @casa_organization = volunteer.casa_org @supervisor = supervisor diff --git a/app/views/supervisor_mailer/reimbursement_request_reminder.html.erb b/app/views/supervisor_mailer/reimbursement_request_email.html.erb similarity index 91% rename from app/views/supervisor_mailer/reimbursement_request_reminder.html.erb rename to app/views/supervisor_mailer/reimbursement_request_email.html.erb index 7ec0044c1b..b964afdf1a 100644 --- a/app/views/supervisor_mailer/reimbursement_request_reminder.html.erb +++ b/app/views/supervisor_mailer/reimbursement_request_email.html.erb @@ -9,7 +9,7 @@ <%= @volunteer.display_name %> has submitted a reimbursement request, please follow up on the reimbursements page - " target="_blank">this link to view reimbursement requests. + " target="_blank">using this link. diff --git a/lib/mailers/previews/supervisor_mailer_preview.rb b/lib/mailers/previews/supervisor_mailer_preview.rb index abf031144e..ebc4bc42c3 100644 --- a/lib/mailers/previews/supervisor_mailer_preview.rb +++ b/lib/mailers/previews/supervisor_mailer_preview.rb @@ -39,11 +39,11 @@ def weekly_digest end end - def reimbursement_request_reminder + def reimbursement_request_email volunteer = params.has_key?(:volunteer_id) ? Volunteer.find_by(id: params[:volunteer_id]) : Volunteer.last supervisor = params.has_key?(:supervisor_id) ? Supervisor.find_by(id: params[:supervisor_id]) : Supervisor.last supervisor.receive_reimbursement_email = true - SupervisorMailer.reimbursement_request_reminder(volunteer, supervisor) + SupervisorMailer.reimbursement_request_email(volunteer, supervisor) end end diff --git a/spec/mailers/previews/supervisor_mailer_preview_spec.rb b/spec/mailers/previews/supervisor_mailer_preview_spec.rb index f6e0d57e61..b666374099 100644 --- a/spec/mailers/previews/supervisor_mailer_preview_spec.rb +++ b/spec/mailers/previews/supervisor_mailer_preview_spec.rb @@ -51,17 +51,17 @@ end end - describe "#reimbursement_request_reminder" do + describe "#reimbursement_request_email" do context "When no ID is passed" do let(:preview) { described_class.new } - let(:email) { preview.reimbursement_request_reminder } + let(:email) { preview.reimbursement_request_email } it { expect(email.to).to eq [supervisor.email] } end context "When passed ID is valid" do let(:preview) { described_class.new(volunteer_id: volunteer.id, supervisor_id: supervisor.id) } - let(:email) { preview.reimbursement_request_reminder } + let(:email) { preview.reimbursement_request_email } it { expect(email.to).to eq [supervisor.email] } end diff --git a/spec/mailers/supervisor_mailer_spec.rb b/spec/mailers/supervisor_mailer_spec.rb index e0229acf75..619eb38423 100644 --- a/spec/mailers/supervisor_mailer_spec.rb +++ b/spec/mailers/supervisor_mailer_spec.rb @@ -117,12 +117,12 @@ end end - describe ".reimbursement_request_reminder" do + describe ".reimbursement_request_email" do let(:supervisor) { create(:supervisor, receive_reimbursement_email: true) } let(:volunteer) { create(:volunteer) } let(:casa_organization) { volunteer.casa_org } - let(:mail) { SupervisorMailer.reimbursement_request_reminder(volunteer, supervisor) } + let(:mail) { SupervisorMailer.reimbursement_request_email(volunteer, supervisor) } it "sends email reminder" do expect(mail.body.encoded).to match("#{volunteer.display_name} has submitted a reimbursement request") From 97f06271ba7909092f615557af6a4ca93e4d16eb Mon Sep 17 00:00:00 2001 From: Nidhi Sarvaiya Date: Thu, 21 Sep 2023 22:23:48 -0400 Subject: [PATCH 3/6] Updated specs to check reimbursement mail condition and other fixes as per PR feedback --- app/controllers/case_contacts_controller.rb | 2 +- .../reimbursement_request_email.html.erb | 2 +- spec/mailers/supervisor_mailer_spec.rb | 2 ++ spec/requests/case_contacts_spec.rb | 26 +++++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/controllers/case_contacts_controller.rb b/app/controllers/case_contacts_controller.rb index ec74e24c06..5d9ff22226 100644 --- a/app/controllers/case_contacts_controller.rb +++ b/app/controllers/case_contacts_controller.rb @@ -187,7 +187,7 @@ def create_case_contact_for_every_selected_casa_case(selected_cases) def send_reimbursement_email(case_contact) if case_contact.want_driving_reimbursement_changed? && case_contact.want_driving_reimbursement? && !current_user.supervisor.blank? - SupervisorMailer.reimbursement_request_email(current_user, current_user.supervisor).deliver + SupervisorMailer.reimbursement_request_email(current_user, current_user.supervisor).deliver_later end end diff --git a/app/views/supervisor_mailer/reimbursement_request_email.html.erb b/app/views/supervisor_mailer/reimbursement_request_email.html.erb index b964afdf1a..4ee598a580 100644 --- a/app/views/supervisor_mailer/reimbursement_request_email.html.erb +++ b/app/views/supervisor_mailer/reimbursement_request_email.html.erb @@ -9,7 +9,7 @@ <%= @volunteer.display_name %> has submitted a reimbursement request, please follow up on the reimbursements page - " target="_blank">using this link. + <%= link_to "using this link", reimbursements_url %>. diff --git a/spec/mailers/supervisor_mailer_spec.rb b/spec/mailers/supervisor_mailer_spec.rb index 619eb38423..9d4ad0454e 100644 --- a/spec/mailers/supervisor_mailer_spec.rb +++ b/spec/mailers/supervisor_mailer_spec.rb @@ -125,6 +125,8 @@ let(:mail) { SupervisorMailer.reimbursement_request_email(volunteer, supervisor) } it "sends email reminder" do + expect(mail.subject).to eq("New reimbursement request from #{volunteer.display_name}") + expect(mail.to).to eq([supervisor.email]) expect(mail.body.encoded).to match("#{volunteer.display_name} has submitted a reimbursement request") end end diff --git a/spec/requests/case_contacts_spec.rb b/spec/requests/case_contacts_spec.rb index 22cefe53f4..014b3a3bbb 100644 --- a/spec/requests/case_contacts_spec.rb +++ b/spec/requests/case_contacts_spec.rb @@ -142,6 +142,32 @@ end end + context "reimbursement mail to supervisor" do + let(:case_contact) {create(:case_contact, :wants_reimbursement, casa_case: casa_case, creator: admin)} + let(:supervisor) {create(:supervisor, receive_email_notifications: true)} + + it "sends reimbursement request email when conditions are met" do + allow(case_contact).to receive(:want_driving_reimbursement?).and_return(true) + allow(admin).to receive(:supervisor).and_return(supervisor) + + mailer_double = double("SupervisorMailer") + allow(SupervisorMailer).to receive(:reimbursement_request_email).and_return(mailer_double) + + expect(mailer_double).to receive(:deliver_later) + request + end + + it "does not send reimbursement request email when conditions are not met" do + allow(case_contact).to receive(:want_driving_reimbursement?).and_return(false) + + mailer_double = double("SupervisorMailer") + allow(SupervisorMailer).to receive(:reimbursement_request_email).and_return(mailer_double) + + expect(mailer_double).not_to receive(:deliver_later) + request + end + end + context "with additional expense" do let(:params) do { From ff586a4f3fe0cb9a96e5b95d7675e3daf799d260 Mon Sep 17 00:00:00 2001 From: Nidhi Sarvaiya Date: Thu, 21 Sep 2023 22:35:11 -0400 Subject: [PATCH 4/6] Ruby Standard Fixes --- spec/requests/case_contacts_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/requests/case_contacts_spec.rb b/spec/requests/case_contacts_spec.rb index 014b3a3bbb..a2a67beac8 100644 --- a/spec/requests/case_contacts_spec.rb +++ b/spec/requests/case_contacts_spec.rb @@ -143,26 +143,26 @@ end context "reimbursement mail to supervisor" do - let(:case_contact) {create(:case_contact, :wants_reimbursement, casa_case: casa_case, creator: admin)} - let(:supervisor) {create(:supervisor, receive_email_notifications: true)} + let(:case_contact) { create(:case_contact, :wants_reimbursement, casa_case: casa_case, creator: admin) } + let(:supervisor) { create(:supervisor, receive_email_notifications: true) } it "sends reimbursement request email when conditions are met" do allow(case_contact).to receive(:want_driving_reimbursement?).and_return(true) allow(admin).to receive(:supervisor).and_return(supervisor) - + mailer_double = double("SupervisorMailer") allow(SupervisorMailer).to receive(:reimbursement_request_email).and_return(mailer_double) - + expect(mailer_double).to receive(:deliver_later) request end it "does not send reimbursement request email when conditions are not met" do allow(case_contact).to receive(:want_driving_reimbursement?).and_return(false) - + mailer_double = double("SupervisorMailer") allow(SupervisorMailer).to receive(:reimbursement_request_email).and_return(mailer_double) - + expect(mailer_double).not_to receive(:deliver_later) request end From 1d8db80c91afcd991945b82d02c25339174b6663 Mon Sep 17 00:00:00 2001 From: Nidhi Sarvaiya Date: Fri, 20 Oct 2023 14:15:58 -0400 Subject: [PATCH 5/6] Updated spec to explicitely map volunteer supervisor --- spec/mailers/previews/supervisor_mailer_preview_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/mailers/previews/supervisor_mailer_preview_spec.rb b/spec/mailers/previews/supervisor_mailer_preview_spec.rb index b666374099..86a6e17582 100644 --- a/spec/mailers/previews/supervisor_mailer_preview_spec.rb +++ b/spec/mailers/previews/supervisor_mailer_preview_spec.rb @@ -3,7 +3,7 @@ RSpec.describe SupervisorMailerPreview do let!(:supervisor) { create(:supervisor) } - let!(:volunteer) { create(:volunteer) } + let!(:volunteer) { create(:volunteer, casa_org: supervisor.casa_org, supervisor: supervisor) } describe "#account_setup" do context "When no ID is passed" do From f35a840b872150380e9e3069b8055a83d29c544e Mon Sep 17 00:00:00 2001 From: Sam Williams Date: Tue, 24 Oct 2023 07:21:01 -0400 Subject: [PATCH 6/6] Email selected users when reimbursement requests are entered // Moved logic to model, fixed tests --- app/controllers/case_contacts_controller.rb | 4 +-- app/models/case_contact.rb | 8 +++++ .../supervisor_mailer_preview_spec.rb | 6 ++-- spec/mailers/supervisor_mailer_spec.rb | 2 +- spec/models/case_contact_spec.rb | 32 +++++++++++++++++++ spec/requests/case_contacts_spec.rb | 17 +++++----- 6 files changed, 55 insertions(+), 14 deletions(-) diff --git a/app/controllers/case_contacts_controller.rb b/app/controllers/case_contacts_controller.rb index 5d9ff22226..cf9db658c1 100644 --- a/app/controllers/case_contacts_controller.rb +++ b/app/controllers/case_contacts_controller.rb @@ -186,8 +186,8 @@ def create_case_contact_for_every_selected_casa_case(selected_cases) end def send_reimbursement_email(case_contact) - if case_contact.want_driving_reimbursement_changed? && case_contact.want_driving_reimbursement? && !current_user.supervisor.blank? - SupervisorMailer.reimbursement_request_email(current_user, current_user.supervisor).deliver_later + if case_contact.should_send_reimbursement_email? + SupervisorMailer.reimbursement_request_email(case_contact.creator, case_contact.supervisor).deliver_later end end diff --git a/app/models/case_contact.rb b/app/models/case_contact.rb index 9d745c16f1..abd4d6b123 100644 --- a/app/models/case_contact.rb +++ b/app/models/case_contact.rb @@ -197,6 +197,14 @@ def requested_followup followups.requested.first end + def should_send_reimbursement_email? + want_driving_reimbursement_changed? && want_driving_reimbursement? && supervisor_active? + end + + def supervisor_active? + !supervisor.blank? && supervisor.active? + end + def self.options_for_sorted_by sorted_by_params.map do |option| [I18n.t("models.case_contact.options_for_sorted_by.#{option}"), option] diff --git a/spec/mailers/previews/supervisor_mailer_preview_spec.rb b/spec/mailers/previews/supervisor_mailer_preview_spec.rb index 86a6e17582..b9f45cc961 100644 --- a/spec/mailers/previews/supervisor_mailer_preview_spec.rb +++ b/spec/mailers/previews/supervisor_mailer_preview_spec.rb @@ -33,21 +33,21 @@ let(:preview) { described_class.new } let(:email) { preview.weekly_digest } - xit { expect(email.to).to eq [supervisor.email] } + it { expect(email.to).to eq [supervisor.email] } end context "When passed ID is valid" do let(:preview) { described_class.new(id: supervisor.id) } let(:email) { preview.weekly_digest } - xit { expect(email.to).to eq [supervisor.email] } + it { expect(email.to).to eq [supervisor.email] } end context "When passed ID is invalid" do let(:preview) { described_class.new(id: 3500) } let(:email) { preview.weekly_digest } - xit { expect(email.to).to eq ["missing_supervisor@example.com"] } + it { expect(email.to).to eq ["missing_supervisor@example.com"] } end end diff --git a/spec/mailers/supervisor_mailer_spec.rb b/spec/mailers/supervisor_mailer_spec.rb index 9d4ad0454e..6aa7a39abb 100644 --- a/spec/mailers/supervisor_mailer_spec.rb +++ b/spec/mailers/supervisor_mailer_spec.rb @@ -119,7 +119,7 @@ describe ".reimbursement_request_email" do let(:supervisor) { create(:supervisor, receive_reimbursement_email: true) } - let(:volunteer) { create(:volunteer) } + let(:volunteer) { create(:volunteer, supervisor: supervisor) } let(:casa_organization) { volunteer.casa_org } let(:mail) { SupervisorMailer.reimbursement_request_email(volunteer, supervisor) } diff --git a/spec/models/case_contact_spec.rb b/spec/models/case_contact_spec.rb index cb0458a9f5..44c57aa6eb 100644 --- a/spec/models/case_contact_spec.rb +++ b/spec/models/case_contact_spec.rb @@ -492,4 +492,36 @@ end end end + + describe "#should_send_reimbursement_email?" do + let(:supervisor) { create(:supervisor, receive_reimbursement_email: true) } + let(:volunteer) { create(:volunteer, supervisor: supervisor) } + let(:case_contact) { build(:case_contact, :wants_reimbursement, creator: volunteer) } + + it "returns true if wants reimbursement, reimbursement changed, and has active supervisor" do + expect(case_contact.should_send_reimbursement_email?).to be true + end + + it "returns false if want reimbursement not changed" do + case_contact.save + expect(case_contact.want_driving_reimbursement_changed?).to be false + expect(case_contact.should_send_reimbursement_email?).to be false + end + + it "returns false if doesn't want reimbursement" do + case_contact.want_driving_reimbursement = false + expect(case_contact.should_send_reimbursement_email?).to be false + end + + it "returns false if creator doesn't have supervisor" do + volunteer.supervisor_volunteer = nil + expect(case_contact.supervisor.blank?).to be true + expect(case_contact.should_send_reimbursement_email?).to be false + end + + it "returns false if creator's supervisor is inactive" do + supervisor.update(active: false) + expect(case_contact.should_send_reimbursement_email?).to be false + end + end end diff --git a/spec/requests/case_contacts_spec.rb b/spec/requests/case_contacts_spec.rb index a2a67beac8..89f50edf43 100644 --- a/spec/requests/case_contacts_spec.rb +++ b/spec/requests/case_contacts_spec.rb @@ -106,7 +106,7 @@ let(:selected_casa_case_ids) { [casa_case.id] } let(:valid_attributes) do attributes_for(:case_contact, :wants_reimbursement, casa_case: casa_case).merge( - creator: admin, casa_case_id: selected_casa_case_ids + casa_case_id: selected_casa_case_ids ) end let(:params) { {case_contact: valid_attributes} } @@ -143,13 +143,15 @@ end context "reimbursement mail to supervisor" do - let(:case_contact) { create(:case_contact, :wants_reimbursement, casa_case: casa_case, creator: admin) } - let(:supervisor) { create(:supervisor, receive_email_notifications: true) } + let(:supervisor) { create(:supervisor, receive_reimbursement_email: true, casa_org: organization) } + let(:volunteer) { create(:volunteer, supervisor: supervisor, casa_org: organization) } + let!(:case_assignment) { create(:case_assignment, volunteer: volunteer, casa_case: casa_case) } - it "sends reimbursement request email when conditions are met" do - allow(case_contact).to receive(:want_driving_reimbursement?).and_return(true) - allow(admin).to receive(:supervisor).and_return(supervisor) + before do + sign_in volunteer + end + it "sends reimbursement request email when conditions are met" do mailer_double = double("SupervisorMailer") allow(SupervisorMailer).to receive(:reimbursement_request_email).and_return(mailer_double) @@ -158,8 +160,7 @@ end it "does not send reimbursement request email when conditions are not met" do - allow(case_contact).to receive(:want_driving_reimbursement?).and_return(false) - + supervisor.update(active: false) mailer_double = double("SupervisorMailer") allow(SupervisorMailer).to receive(:reimbursement_request_email).and_return(mailer_double)