From 4699e515edbc97fe194125893d9b7aaca9ba5fcd Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 22 Nov 2018 18:11:00 +0100 Subject: [PATCH] [Fix #2999] Send gestionnaire back to what they were doing after email verification --- app/controllers/users/sessions_controller.rb | 8 +++----- spec/controllers/users/sessions_controller_spec.rb | 4 +++- spec/features/new_gestionnaire/gestionnaire_spec.rb | 13 +++++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index f8ca9fe9f..87f312d51 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -94,11 +94,9 @@ class Users::SessionsController < Sessions::SessionsController administrateur = Administrateur.find_by(email: gestionnaire.email) [user, gestionnaire, administrateur].compact.each { |resource| sign_in(resource) } - if administrateur.present? - redirect_to admin_procedures_path - else - redirect_to gestionnaire_procedures_path - end + # redirect to procedure'url if stored by store_location_for(:user) in dossiers_controller + # redirect to root_path otherwise + redirect_to after_sign_in_path_for(:user) else flash[:alert] = 'Votre lien est invalide ou expiré, veuillez-vous reconnecter.' redirect_to new_user_session_path diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index 8d55ac53f..608791878 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -261,7 +261,9 @@ describe Users::SessionsController, type: :controller do context 'when the token is valid' do let(:login_token) { gestionnaire.login_token! } - it { is_expected.to redirect_to gestionnaire_procedures_path } + # TODO when the gestionnaire has no other account, and the token is valid, and the user signing in was not starting a demarche, + # redirect to root_path, then redirect to gestionnaire_procedures_path (see root_controller) + it { is_expected.to redirect_to root_path } it { expect(controller.current_gestionnaire).to eq(gestionnaire) } it { expect(controller).to have_received(:trust_device) } end diff --git a/spec/features/new_gestionnaire/gestionnaire_spec.rb b/spec/features/new_gestionnaire/gestionnaire_spec.rb index e38f6c3f7..220d28d93 100644 --- a/spec/features/new_gestionnaire/gestionnaire_spec.rb +++ b/spec/features/new_gestionnaire/gestionnaire_spec.rb @@ -9,6 +9,19 @@ feature 'The gestionnaire part' do let!(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) } let!(:dossier) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure) } + context 'when the gestionnaire is also a user' do + let!(:user) { create(:user, email: gestionnaire.email, password: password) } + + scenario 'a gestionnaire can fill a dossier' do + visit commencer_path(path: procedure.path) + + expect(page).to have_current_path new_user_session_path + sign_in_with(gestionnaire.email, password, true) + + expect(page).to have_content(procedure.libelle) + end + end + scenario 'A gestionnaire can accept a dossier', :js do log_in(gestionnaire.email, password)