Fix expert invitation
This commit is contained in:
parent
fdbfd3bb42
commit
8fa3c9e4f7
2 changed files with 14 additions and 9 deletions
|
@ -83,21 +83,26 @@ module Instructeurs
|
|||
email = params[:email]
|
||||
password = params['instructeur']['password']
|
||||
|
||||
instructeur = Instructeur.new(email: email, password: password)
|
||||
|
||||
if instructeur.save
|
||||
user = User.find_by(email: email)
|
||||
if user.blank?
|
||||
user = User.create(email: email, password: password, confirmed_at: Time.zone.now)
|
||||
|
||||
if user.nil?
|
||||
user = User.create(
|
||||
email: email,
|
||||
password: password,
|
||||
confirmed_at: Time.zone.now
|
||||
)
|
||||
end
|
||||
|
||||
if user.errors.empty?
|
||||
instructeur = Instructeur.create(email: email)
|
||||
user.update!(instructeur: instructeur)
|
||||
|
||||
sign_in(user)
|
||||
sign_in(instructeur, scope: :instructeur)
|
||||
|
||||
Avis.link_avis_to_instructeur(instructeur)
|
||||
redirect_to url_for(instructeur_avis_index_path)
|
||||
else
|
||||
flash[:alert] = instructeur.errors.full_messages
|
||||
flash[:alert] = user.errors.full_messages
|
||||
redirect_to url_for(sign_up_instructeur_avis_path(params[:id], email))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -282,7 +282,7 @@ describe Instructeurs::AvisController, type: :controller do
|
|||
context 'when the email belongs to the invitation' do
|
||||
context 'when the instructeur creation succeeds' do
|
||||
it { expect(created_instructeur).to be_present }
|
||||
it { expect(created_instructeur.valid_password?(password)).to be true }
|
||||
it { expect(created_instructeur.user.valid_password?(password)).to be true }
|
||||
|
||||
it { expect(Avis).to have_received(:link_avis_to_instructeur) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue