Add email_spec
and speedup/cleanup to spec/mailers
(#27902)
This commit is contained in:
parent
9c68741f46
commit
549e8e7baf
7 changed files with 194 additions and 152 deletions
|
@ -10,9 +10,12 @@ describe UserMailer do
|
|||
|
||||
it 'renders confirmation instructions' do
|
||||
receiver.update!(locale: nil)
|
||||
expect(mail.body.encoded).to include I18n.t('devise.mailer.confirmation_instructions.title')
|
||||
expect(mail.body.encoded).to include 'spec'
|
||||
expect(mail.body.encoded).to include Rails.configuration.x.local_domain
|
||||
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_body_text(I18n.t('devise.mailer.confirmation_instructions.title')))
|
||||
.and(have_body_text('spec'))
|
||||
.and(have_body_text(Rails.configuration.x.local_domain))
|
||||
end
|
||||
|
||||
include_examples 'localized subject',
|
||||
|
@ -25,13 +28,17 @@ describe UserMailer do
|
|||
|
||||
it 'renders reconfirmation instructions' do
|
||||
receiver.update!(email: 'new-email@example.com', locale: nil)
|
||||
expect(mail.body.encoded).to include I18n.t('devise.mailer.reconfirmation_instructions.title')
|
||||
expect(mail.body.encoded).to include 'spec'
|
||||
expect(mail.body.encoded).to include Rails.configuration.x.local_domain
|
||||
expect(mail.subject).to eq I18n.t('devise.mailer.reconfirmation_instructions.subject',
|
||||
instance: Rails.configuration.x.local_domain,
|
||||
locale: I18n.default_locale)
|
||||
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_body_text(I18n.t('devise.mailer.reconfirmation_instructions.title')))
|
||||
.and(have_body_text('spec'))
|
||||
.and(have_body_text(Rails.configuration.x.local_domain))
|
||||
end
|
||||
|
||||
include_examples 'localized subject',
|
||||
'devise.mailer.confirmation_instructions.subject',
|
||||
instance: Rails.configuration.x.local_domain
|
||||
end
|
||||
|
||||
describe '#reset_password_instructions' do
|
||||
|
@ -39,8 +46,11 @@ describe UserMailer do
|
|||
|
||||
it 'renders reset password instructions' do
|
||||
receiver.update!(locale: nil)
|
||||
expect(mail.body.encoded).to include I18n.t('devise.mailer.reset_password_instructions.title')
|
||||
expect(mail.body.encoded).to include 'spec'
|
||||
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_body_text(I18n.t('devise.mailer.reset_password_instructions.title')))
|
||||
.and(have_body_text('spec'))
|
||||
end
|
||||
|
||||
include_examples 'localized subject',
|
||||
|
@ -52,7 +62,10 @@ describe UserMailer do
|
|||
|
||||
it 'renders password change notification' do
|
||||
receiver.update!(locale: nil)
|
||||
expect(mail.body.encoded).to include I18n.t('devise.mailer.password_change.title')
|
||||
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_body_text(I18n.t('devise.mailer.password_change.title')))
|
||||
end
|
||||
|
||||
include_examples 'localized subject',
|
||||
|
@ -64,7 +77,10 @@ describe UserMailer do
|
|||
|
||||
it 'renders email change notification' do
|
||||
receiver.update!(locale: nil)
|
||||
expect(mail.body.encoded).to include I18n.t('devise.mailer.email_changed.title')
|
||||
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_body_text(I18n.t('devise.mailer.email_changed.title')))
|
||||
end
|
||||
|
||||
include_examples 'localized subject',
|
||||
|
@ -77,8 +93,11 @@ describe UserMailer do
|
|||
|
||||
it 'renders warning notification' do
|
||||
receiver.update!(locale: nil)
|
||||
expect(mail.body.encoded).to include I18n.t('user_mailer.warning.title.suspend', acct: receiver.account.acct)
|
||||
expect(mail.body.encoded).to include strike.text
|
||||
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_body_text(I18n.t('user_mailer.warning.title.suspend', acct: receiver.account.acct)))
|
||||
.and(have_body_text(strike.text))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -88,7 +107,10 @@ describe UserMailer do
|
|||
|
||||
it 'renders webauthn credential deleted notification' do
|
||||
receiver.update!(locale: nil)
|
||||
expect(mail.body.encoded).to include I18n.t('devise.mailer.webauthn_credential.deleted.title')
|
||||
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_body_text(I18n.t('devise.mailer.webauthn_credential.deleted.title')))
|
||||
end
|
||||
|
||||
include_examples 'localized subject',
|
||||
|
@ -103,7 +125,10 @@ describe UserMailer do
|
|||
|
||||
it 'renders suspicious sign in notification' do
|
||||
receiver.update!(locale: nil)
|
||||
expect(mail.body.encoded).to include I18n.t('user_mailer.suspicious_sign_in.explanation')
|
||||
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_body_text(I18n.t('user_mailer.suspicious_sign_in.explanation')))
|
||||
end
|
||||
|
||||
include_examples 'localized subject',
|
||||
|
@ -115,8 +140,10 @@ describe UserMailer do
|
|||
let(:mail) { described_class.appeal_approved(receiver, appeal) }
|
||||
|
||||
it 'renders appeal_approved notification' do
|
||||
expect(mail.subject).to eq I18n.t('user_mailer.appeal_approved.subject', date: I18n.l(appeal.created_at))
|
||||
expect(mail.body.encoded).to include I18n.t('user_mailer.appeal_approved.title')
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_subject(I18n.t('user_mailer.appeal_approved.subject', date: I18n.l(appeal.created_at))))
|
||||
.and(have_body_text(I18n.t('user_mailer.appeal_approved.title')))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -125,8 +152,10 @@ describe UserMailer do
|
|||
let(:mail) { described_class.appeal_rejected(receiver, appeal) }
|
||||
|
||||
it 'renders appeal_rejected notification' do
|
||||
expect(mail.subject).to eq I18n.t('user_mailer.appeal_rejected.subject', date: I18n.l(appeal.created_at))
|
||||
expect(mail.body.encoded).to include I18n.t('user_mailer.appeal_rejected.title')
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_subject(I18n.t('user_mailer.appeal_rejected.subject', date: I18n.l(appeal.created_at))))
|
||||
.and(have_body_text(I18n.t('user_mailer.appeal_rejected.title')))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -134,8 +163,10 @@ describe UserMailer do
|
|||
let(:mail) { described_class.two_factor_enabled(receiver) }
|
||||
|
||||
it 'renders two_factor_enabled mail' do
|
||||
expect(mail.subject).to eq I18n.t('devise.mailer.two_factor_enabled.subject')
|
||||
expect(mail.body.encoded).to include I18n.t('devise.mailer.two_factor_enabled.explanation')
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_subject(I18n.t('devise.mailer.two_factor_enabled.subject')))
|
||||
.and(have_body_text(I18n.t('devise.mailer.two_factor_enabled.explanation')))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -143,8 +174,10 @@ describe UserMailer do
|
|||
let(:mail) { described_class.two_factor_disabled(receiver) }
|
||||
|
||||
it 'renders two_factor_disabled mail' do
|
||||
expect(mail.subject).to eq I18n.t('devise.mailer.two_factor_disabled.subject')
|
||||
expect(mail.body.encoded).to include I18n.t('devise.mailer.two_factor_disabled.explanation')
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_subject(I18n.t('devise.mailer.two_factor_disabled.subject')))
|
||||
.and(have_body_text(I18n.t('devise.mailer.two_factor_disabled.explanation')))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -152,8 +185,10 @@ describe UserMailer do
|
|||
let(:mail) { described_class.webauthn_enabled(receiver) }
|
||||
|
||||
it 'renders webauthn_enabled mail' do
|
||||
expect(mail.subject).to eq I18n.t('devise.mailer.webauthn_enabled.subject')
|
||||
expect(mail.body.encoded).to include I18n.t('devise.mailer.webauthn_enabled.explanation')
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_subject(I18n.t('devise.mailer.webauthn_enabled.subject')))
|
||||
.and(have_body_text(I18n.t('devise.mailer.webauthn_enabled.explanation')))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -161,8 +196,10 @@ describe UserMailer do
|
|||
let(:mail) { described_class.webauthn_disabled(receiver) }
|
||||
|
||||
it 'renders webauthn_disabled mail' do
|
||||
expect(mail.subject).to eq I18n.t('devise.mailer.webauthn_disabled.subject')
|
||||
expect(mail.body.encoded).to include I18n.t('devise.mailer.webauthn_disabled.explanation')
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_subject(I18n.t('devise.mailer.webauthn_disabled.subject')))
|
||||
.and(have_body_text(I18n.t('devise.mailer.webauthn_disabled.explanation')))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -170,8 +207,10 @@ describe UserMailer do
|
|||
let(:mail) { described_class.two_factor_recovery_codes_changed(receiver) }
|
||||
|
||||
it 'renders two_factor_recovery_codes_changed mail' do
|
||||
expect(mail.subject).to eq I18n.t('devise.mailer.two_factor_recovery_codes_changed.subject')
|
||||
expect(mail.body.encoded).to include I18n.t('devise.mailer.two_factor_recovery_codes_changed.explanation')
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.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')))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -180,8 +219,10 @@ describe UserMailer do
|
|||
let(:mail) { described_class.webauthn_credential_added(receiver, credential) }
|
||||
|
||||
it 'renders webauthn_credential_added mail' do
|
||||
expect(mail.subject).to eq I18n.t('devise.mailer.webauthn_credential.added.subject')
|
||||
expect(mail.body.encoded).to include I18n.t('devise.mailer.webauthn_credential.added.explanation')
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_subject(I18n.t('devise.mailer.webauthn_credential.added.subject')))
|
||||
.and(have_body_text(I18n.t('devise.mailer.webauthn_credential.added.explanation')))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -189,8 +230,10 @@ describe UserMailer do
|
|||
let(:mail) { described_class.welcome(receiver) }
|
||||
|
||||
it 'renders welcome mail' do
|
||||
expect(mail.subject).to eq I18n.t('user_mailer.welcome.subject')
|
||||
expect(mail.body.encoded).to include I18n.t('user_mailer.welcome.explanation')
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_subject(I18n.t('user_mailer.welcome.subject')))
|
||||
.and(have_body_text(I18n.t('user_mailer.welcome.explanation')))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -199,8 +242,10 @@ describe UserMailer do
|
|||
let(:mail) { described_class.backup_ready(receiver, backup) }
|
||||
|
||||
it 'renders backup_ready mail' do
|
||||
expect(mail.subject).to eq I18n.t('user_mailer.backup_ready.subject')
|
||||
expect(mail.body.encoded).to include I18n.t('user_mailer.backup_ready.explanation')
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_subject(I18n.t('user_mailer.backup_ready.subject')))
|
||||
.and(have_body_text(I18n.t('user_mailer.backup_ready.explanation')))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue