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]
|
email = params[:email]
|
||||||
password = params['instructeur']['password']
|
password = params['instructeur']['password']
|
||||||
|
|
||||||
instructeur = Instructeur.new(email: email, password: password)
|
user = User.find_by(email: email)
|
||||||
|
|
||||||
if instructeur.save
|
if user.nil?
|
||||||
user = User.find_by(email: email)
|
user = User.create(
|
||||||
if user.blank?
|
email: email,
|
||||||
user = User.create(email: email, password: password, confirmed_at: Time.zone.now)
|
password: password,
|
||||||
end
|
confirmed_at: Time.zone.now
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
if user.errors.empty?
|
||||||
|
instructeur = Instructeur.create(email: email)
|
||||||
|
user.update!(instructeur: instructeur)
|
||||||
|
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
sign_in(instructeur, scope: :instructeur)
|
|
||||||
|
|
||||||
Avis.link_avis_to_instructeur(instructeur)
|
Avis.link_avis_to_instructeur(instructeur)
|
||||||
redirect_to url_for(instructeur_avis_index_path)
|
redirect_to url_for(instructeur_avis_index_path)
|
||||||
else
|
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))
|
redirect_to url_for(sign_up_instructeur_avis_path(params[:id], email))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -282,7 +282,7 @@ describe Instructeurs::AvisController, type: :controller do
|
||||||
context 'when the email belongs to the invitation' do
|
context 'when the email belongs to the invitation' do
|
||||||
context 'when the instructeur creation succeeds' do
|
context 'when the instructeur creation succeeds' do
|
||||||
it { expect(created_instructeur).to be_present }
|
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) }
|
it { expect(Avis).to have_received(:link_avis_to_instructeur) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue