Also create users for avis gestionnaires
This commit is contained in:
parent
ff3dc32de3
commit
35e1030eed
2 changed files with 22 additions and 0 deletions
|
@ -87,7 +87,14 @@ module NewGestionnaire
|
|||
gestionnaire = Gestionnaire.new(email: email, password: password)
|
||||
|
||||
if gestionnaire.save
|
||||
user = User.find_by(email: email)
|
||||
if user.blank?
|
||||
user = User.create(email: email, password: password)
|
||||
end
|
||||
|
||||
sign_in(user)
|
||||
sign_in(gestionnaire, scope: :gestionnaire)
|
||||
|
||||
Avis.link_avis_to_gestionnaire(gestionnaire)
|
||||
avis = Avis.find(params[:id])
|
||||
redirect_to url_for(gestionnaire_avis_index_path)
|
||||
|
|
|
@ -216,6 +216,8 @@ describe NewGestionnaire::AvisController, type: :controller do
|
|||
end
|
||||
|
||||
describe '#create_gestionnaire' do
|
||||
let(:existing_user_mail) { 'dummy@example.org' }
|
||||
let!(:existing_user) { create(:user, email: existing_user_mail) }
|
||||
let(:invited_email) { 'invited@avis.com' }
|
||||
let(:dossier) { create(:dossier) }
|
||||
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
|
||||
|
@ -254,6 +256,19 @@ describe NewGestionnaire::AvisController, type: :controller do
|
|||
|
||||
it { expect(subject.current_gestionnaire).to eq(created_gestionnaire) }
|
||||
it { is_expected.to redirect_to gestionnaire_avis_index_path }
|
||||
|
||||
it 'creates a corresponding user account for the email' do
|
||||
user = User.find_by(email: invited_email)
|
||||
expect(user).to be_present
|
||||
end
|
||||
|
||||
context 'when there already is a user account with the same email' do
|
||||
let(:existing_user_mail) { invited_email }
|
||||
|
||||
it 'still creates a gestionnaire account' do
|
||||
expect(created_gestionnaire).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the gestionnaire creation fails' do
|
||||
|
|
Loading…
Add table
Reference in a new issue