refactor(groupe instructeur mailer): rename mailer methods

This commit is contained in:
Eric Leroy-Terquem 2023-02-14 15:19:58 +01:00
parent cbf072961c
commit 5be58c8223
13 changed files with 38 additions and 38 deletions

View file

@ -321,7 +321,7 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
context 'when there are many instructeurs' do
before do
allow(GroupeInstructeurMailer).to receive(:remove_instructeur)
allow(GroupeInstructeurMailer).to receive(:notify_removed_instructeurs)
.and_return(double(deliver_later: true))
remove_instructeur(admin.instructeur)
end
@ -330,7 +330,7 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
it { expect(gi_1_1.reload.instructeurs.count).to eq(1) }
it { expect(response).to redirect_to(admin_procedure_groupe_instructeur_path(procedure, gi_1_1)) }
it "calls GroupeInstructeurMailer with the right groupe and instructeur" do
expect(GroupeInstructeurMailer).to have_received(:remove_instructeur).with(
expect(GroupeInstructeurMailer).to have_received(:notify_removed_instructeurs).with(
gi_1_1,
[admin.instructeur],
admin.email

View file

@ -1,5 +1,5 @@
RSpec.describe GroupeInstructeurMailer, type: :mailer do
describe '#remove_instructeurs' do
describe '#notify_group_when_instructeurs_removed' do
let(:groupe_instructeur) do
gi = GroupeInstructeur.create(label: 'gi1', procedure: create(:procedure))
gi.instructeurs << create(:instructeur, email: 'int1@g')
@ -13,13 +13,13 @@ RSpec.describe GroupeInstructeurMailer, type: :mailer do
let(:instructeurs_to_remove) { [instructeur_3, instructeur_4] }
let(:current_instructeur_email) { 'toto@email.com' }
subject { described_class.remove_instructeurs(groupe_instructeur, instructeurs_to_remove, current_instructeur_email) }
subject { described_class.notify_group_when_instructeurs_removed(groupe_instructeur, instructeurs_to_remove, current_instructeur_email) }
it { expect(subject.body).to include('Les instructeurs int3@g, int4@g ont été retirés du groupe') }
it { expect(subject.bcc).to include('int1@g', 'int2@g') }
end
describe '#remove_instructeur' do
describe '#notify_removed_instructeurs' do
let(:groupe_instructeur) do
gi = GroupeInstructeur.create(label: 'gi1', procedure: create(:procedure))
gi.instructeurs << create(:instructeur, email: 'int1@g')
@ -33,7 +33,7 @@ RSpec.describe GroupeInstructeurMailer, type: :mailer do
let(:instructeurs_to_remove) { [instructeur_3, instructeur_4] }
let(:current_instructeur_email) { 'toto@email.com' }
subject { described_class.remove_instructeur(groupe_instructeur, instructeurs_to_remove, current_instructeur_email) }
subject { described_class.notify_removed_instructeurs(groupe_instructeur, instructeurs_to_remove, current_instructeur_email) }
it { expect(subject.body).to include('ous avez été retiré du groupe « gi1 » par « toto@email.com »') }
it { expect(subject.bcc).to match_array(['int3@g', 'int4@g']) }

View file

@ -4,7 +4,7 @@ class GroupeInstructeurMailerPreview < ActionMailer::Preview
groupe = GroupeInstructeur.new(id: 1, label: 'Val-De-Marne', procedure:)
current_instructeur_email = 'admin@dgfip.com'
instructeurs = Instructeur.limit(2)
GroupeInstructeurMailer.remove_instructeurs(groupe, instructeurs, current_instructeur_email)
GroupeInstructeurMailer.notify_group_when_instructeurs_removed(groupe, instructeurs, current_instructeur_email)
end
def remove_instructeur