Add coverage for UserMailer not delivering to memorialized users (#33366)

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Matt Jankowski 2024-12-20 05:27:40 -05:00 committed by GitHub
parent aa455aaa49
commit d31d988e24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,17 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe UserMailer do RSpec.describe UserMailer do
shared_examples 'delivery to memorialized user' do
context 'when the account is memorialized' do
before { receiver.account.update(memorial: true) }
it 'does not deliver mail' do
emails = capture_emails { mail.deliver_now }
expect(emails).to be_empty
end
end
end
let(:receiver) { Fabricate(:user) } let(:receiver) { Fabricate(:user) }
describe '#confirmation_instructions' do describe '#confirmation_instructions' do
@ -21,6 +32,7 @@ RSpec.describe UserMailer do
include_examples 'localized subject', include_examples 'localized subject',
'devise.mailer.confirmation_instructions.subject', 'devise.mailer.confirmation_instructions.subject',
instance: Rails.configuration.x.local_domain instance: Rails.configuration.x.local_domain
include_examples 'delivery to memorialized user'
end end
describe '#reconfirmation_instructions' do describe '#reconfirmation_instructions' do
@ -39,6 +51,7 @@ RSpec.describe UserMailer do
include_examples 'localized subject', include_examples 'localized subject',
'devise.mailer.confirmation_instructions.subject', 'devise.mailer.confirmation_instructions.subject',
instance: Rails.configuration.x.local_domain instance: Rails.configuration.x.local_domain
include_examples 'delivery to memorialized user'
end end
describe '#reset_password_instructions' do describe '#reset_password_instructions' do
@ -55,6 +68,7 @@ RSpec.describe UserMailer do
include_examples 'localized subject', include_examples 'localized subject',
'devise.mailer.reset_password_instructions.subject' 'devise.mailer.reset_password_instructions.subject'
include_examples 'delivery to memorialized user'
end end
describe '#password_change' do describe '#password_change' do
@ -70,6 +84,7 @@ RSpec.describe UserMailer do
include_examples 'localized subject', include_examples 'localized subject',
'devise.mailer.password_change.subject' 'devise.mailer.password_change.subject'
include_examples 'delivery to memorialized user'
end end
describe '#email_changed' do describe '#email_changed' do
@ -85,6 +100,7 @@ RSpec.describe UserMailer do
include_examples 'localized subject', include_examples 'localized subject',
'devise.mailer.email_changed.subject' 'devise.mailer.email_changed.subject'
include_examples 'delivery to memorialized user'
end end
describe '#warning' do describe '#warning' do
@ -115,6 +131,7 @@ RSpec.describe UserMailer do
include_examples 'localized subject', include_examples 'localized subject',
'devise.mailer.webauthn_credential.deleted.subject' 'devise.mailer.webauthn_credential.deleted.subject'
include_examples 'delivery to memorialized user'
end end
describe '#suspicious_sign_in' do describe '#suspicious_sign_in' do
@ -186,6 +203,8 @@ RSpec.describe UserMailer do
.and(have_subject(I18n.t('devise.mailer.two_factor_enabled.subject'))) .and(have_subject(I18n.t('devise.mailer.two_factor_enabled.subject')))
.and(have_body_text(I18n.t('devise.mailer.two_factor_enabled.explanation'))) .and(have_body_text(I18n.t('devise.mailer.two_factor_enabled.explanation')))
end end
include_examples 'delivery to memorialized user'
end end
describe '#two_factor_disabled' do describe '#two_factor_disabled' do
@ -197,6 +216,8 @@ RSpec.describe UserMailer do
.and(have_subject(I18n.t('devise.mailer.two_factor_disabled.subject'))) .and(have_subject(I18n.t('devise.mailer.two_factor_disabled.subject')))
.and(have_body_text(I18n.t('devise.mailer.two_factor_disabled.explanation'))) .and(have_body_text(I18n.t('devise.mailer.two_factor_disabled.explanation')))
end end
include_examples 'delivery to memorialized user'
end end
describe '#webauthn_enabled' do describe '#webauthn_enabled' do
@ -208,6 +229,8 @@ RSpec.describe UserMailer do
.and(have_subject(I18n.t('devise.mailer.webauthn_enabled.subject'))) .and(have_subject(I18n.t('devise.mailer.webauthn_enabled.subject')))
.and(have_body_text(I18n.t('devise.mailer.webauthn_enabled.explanation'))) .and(have_body_text(I18n.t('devise.mailer.webauthn_enabled.explanation')))
end end
include_examples 'delivery to memorialized user'
end end
describe '#webauthn_disabled' do describe '#webauthn_disabled' do
@ -219,6 +242,8 @@ RSpec.describe UserMailer do
.and(have_subject(I18n.t('devise.mailer.webauthn_disabled.subject'))) .and(have_subject(I18n.t('devise.mailer.webauthn_disabled.subject')))
.and(have_body_text(I18n.t('devise.mailer.webauthn_disabled.explanation'))) .and(have_body_text(I18n.t('devise.mailer.webauthn_disabled.explanation')))
end end
include_examples 'delivery to memorialized user'
end end
describe '#two_factor_recovery_codes_changed' do describe '#two_factor_recovery_codes_changed' do
@ -230,6 +255,8 @@ RSpec.describe UserMailer do
.and(have_subject(I18n.t('devise.mailer.two_factor_recovery_codes_changed.subject'))) .and(have_subject(I18n.t('devise.mailer.two_factor_recovery_codes_changed.subject')))
.and(have_body_text(I18n.t('devise.mailer.two_factor_recovery_codes_changed.explanation'))) .and(have_body_text(I18n.t('devise.mailer.two_factor_recovery_codes_changed.explanation')))
end end
include_examples 'delivery to memorialized user'
end end
describe '#webauthn_credential_added' do describe '#webauthn_credential_added' do
@ -242,6 +269,8 @@ RSpec.describe UserMailer do
.and(have_subject(I18n.t('devise.mailer.webauthn_credential.added.subject'))) .and(have_subject(I18n.t('devise.mailer.webauthn_credential.added.subject')))
.and(have_body_text(I18n.t('devise.mailer.webauthn_credential.added.explanation'))) .and(have_body_text(I18n.t('devise.mailer.webauthn_credential.added.explanation')))
end end
include_examples 'delivery to memorialized user'
end end
describe '#welcome' do describe '#welcome' do
@ -259,6 +288,8 @@ RSpec.describe UserMailer do
.and(have_subject(I18n.t('user_mailer.welcome.subject'))) .and(have_subject(I18n.t('user_mailer.welcome.subject')))
.and(have_body_text(I18n.t('user_mailer.welcome.explanation'))) .and(have_body_text(I18n.t('user_mailer.welcome.explanation')))
end end
include_examples 'delivery to memorialized user'
end end
describe '#backup_ready' do describe '#backup_ready' do
@ -271,6 +302,8 @@ RSpec.describe UserMailer do
.and(have_subject(I18n.t('user_mailer.backup_ready.subject'))) .and(have_subject(I18n.t('user_mailer.backup_ready.subject')))
.and(have_body_text(I18n.t('user_mailer.backup_ready.explanation'))) .and(have_body_text(I18n.t('user_mailer.backup_ready.explanation')))
end end
include_examples 'delivery to memorialized user'
end end
describe '#terms_of_service_changed' do describe '#terms_of_service_changed' do