Merge pull request #10096 from colinux/fix-add-instructeur-without-valid-email
ETQ instructeur je ne dois pas pouvoir inviter un instructeur avec une adresse email invalide
This commit is contained in:
commit
745d7d62b5
2 changed files with 15 additions and 3 deletions
|
@ -22,7 +22,9 @@ module Instructeurs
|
||||||
instructeur = Instructeur.by_email(instructeur_email) ||
|
instructeur = Instructeur.by_email(instructeur_email) ||
|
||||||
create_instructeur(instructeur_email)
|
create_instructeur(instructeur_email)
|
||||||
|
|
||||||
if groupe_instructeur.instructeurs.include?(instructeur)
|
if instructeur.blank?
|
||||||
|
flash[:alert] = "L’adresse email « #{instructeur_email} » n’est pas valide."
|
||||||
|
elsif groupe_instructeur.instructeurs.include?(instructeur)
|
||||||
flash[:alert] = "L’instructeur « #{instructeur_email} » est déjà dans le groupe."
|
flash[:alert] = "L’instructeur « #{instructeur_email} » est déjà dans le groupe."
|
||||||
else
|
else
|
||||||
groupe_instructeur.add(instructeur)
|
groupe_instructeur.add(instructeur)
|
||||||
|
@ -62,7 +64,8 @@ module Instructeurs
|
||||||
SecureRandom.hex,
|
SecureRandom.hex,
|
||||||
administrateurs: [procedure.administrateurs.first]
|
administrateurs: [procedure.administrateurs.first]
|
||||||
)
|
)
|
||||||
user.invite!
|
|
||||||
|
user.invite! if user.valid?
|
||||||
user.instructeur
|
user.instructeur
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ describe Instructeurs::GroupeInstructeursController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#add_instructeur' do
|
describe '#add_instructeur' do
|
||||||
before do
|
subject do
|
||||||
post :add_instructeur,
|
post :add_instructeur,
|
||||||
params: {
|
params: {
|
||||||
procedure_id: procedure.id,
|
procedure_id: procedure.id,
|
||||||
|
@ -83,6 +83,7 @@ describe Instructeurs::GroupeInstructeursController, type: :controller do
|
||||||
|
|
||||||
context 'of a new instructeur' do
|
context 'of a new instructeur' do
|
||||||
let(:new_instructeur_email) { 'new_instructeur@mail.com' }
|
let(:new_instructeur_email) { 'new_instructeur@mail.com' }
|
||||||
|
before { subject }
|
||||||
|
|
||||||
it { expect(gi_1_2.instructeurs.map(&:email)).to include(new_instructeur_email) }
|
it { expect(gi_1_2.instructeurs.map(&:email)).to include(new_instructeur_email) }
|
||||||
it { expect(flash.notice).to be_present }
|
it { expect(flash.notice).to be_present }
|
||||||
|
@ -91,10 +92,18 @@ describe Instructeurs::GroupeInstructeursController, type: :controller do
|
||||||
|
|
||||||
context 'of an instructeur already in the group' do
|
context 'of an instructeur already in the group' do
|
||||||
let(:new_instructeur_email) { instructeur.email }
|
let(:new_instructeur_email) { instructeur.email }
|
||||||
|
before { subject }
|
||||||
|
|
||||||
it { expect(flash.alert).to be_present }
|
it { expect(flash.alert).to be_present }
|
||||||
it { expect(response).to redirect_to(instructeur_groupe_path(procedure, gi_1_2)) }
|
it { expect(response).to redirect_to(instructeur_groupe_path(procedure, gi_1_2)) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'invalid email' do
|
||||||
|
let(:new_instructeur_email) { 'invalid' }
|
||||||
|
|
||||||
|
it { subject; expect(flash.alert).to include(new_instructeur_email) }
|
||||||
|
it { expect { subject }.not_to enqueue_email }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#remove_instructeur' do
|
describe '#remove_instructeur' do
|
||||||
|
|
Loading…
Add table
Reference in a new issue