Skip to content

Commit

Permalink
Réenvoie les emails d'accueil quand l'utilisateur change d'email
Browse files Browse the repository at this point in the history
  • Loading branch information
etienneCharignon committed Aug 28, 2023
1 parent 30ad762 commit 547b2de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/concerns/comptes/envoie_emails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ module EnvoieEmails
private

def after_commit
return if email_bienvenue_envoye? || email_non_confirme? || structure.blank? || superadmin?
if email_non_confirme?
update(email_bienvenue_envoye: false) if email_bienvenue_envoye?
return
end

return if email_bienvenue_envoye? || structure.blank? || superadmin?

envoie_bienvenue(self)
alerte_admins(self) if validation_en_attente?
Expand Down
8 changes: 8 additions & 0 deletions spec/integrations/compte_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
.to have_enqueued_mail(CompteMailer, :nouveau_compte).exactly(1)
end

it "Réenvoie les emails d'accueil quand l'utilisateur change d'email" do
compte = create :compte_admin, structure: structure, confirmed_at: Time.zone.now
compte.update(email: 'nouvel_email@ut7.fr')
expect(compte.reload.email_non_confirme?).to be(true)
expect { compte.update(confirmed_at: Time.zone.now, unconfirmed_email: nil) }
.to have_enqueued_mail(CompteMailer, :nouveau_compte).exactly(1)
end

describe "ne programme pas d'email" do
it 'Quand les mails ont déjà été envoyé' do
compte = create :compte_admin, structure: structure, confirmed_at: Time.zone.now
Expand Down

0 comments on commit 547b2de

Please sign in to comment.