FIX: "confirm new email" emails were failing for EmailChangeRequest records with blank requested_by_user_id field (#12579)

This commit is contained in:
Arpit Jalan 2021-04-01 16:39:28 +05:30 committed by GitHub
parent 61860098d9
commit 3db08c073b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -13,7 +13,7 @@ class EmailChangeRequest < ActiveRecord::Base
end
def requested_by_admin?
self.requested_by.admin? && !self.requested_by_self?
self.requested_by&.admin? && !self.requested_by_self?
end
def requested_by_self?

View File

@ -321,6 +321,15 @@ describe Jobs::UserEmail do
expect(mail.body).not_to include("This email change was requested by a site admin.")
end
end
context "when requested_by record is not present" do
let(:requested_by) { nil }
it "passes along false for the requested_by_admin param which changes the wording in the email" do
Jobs::UserEmail.new.execute(type: :confirm_new_email, user_id: user.id, email_token: email_token.token)
mail = ActionMailer::Base.deliveries.first
expect(mail.body).not_to include("This email change was requested by a site admin.")
end
end
end
context "post" do