commencer: redirect to the procedure page after sign-in and sign-up
This commit is contained in:
parent
016e5f2e6f
commit
bb753ce23e
11 changed files with 62 additions and 27 deletions
|
@ -5,8 +5,8 @@ module ProcedureContextConcern
|
|||
include Devise::StoreLocationExtension
|
||||
|
||||
def restore_procedure_context
|
||||
if stored_procedure_id.present?
|
||||
@procedure = Procedure.publiees.find_by(id: stored_procedure_id)
|
||||
if has_stored_procedure_path?
|
||||
@procedure = find_procedure_in_context
|
||||
|
||||
if @procedure.blank?
|
||||
invalid_procedure_context
|
||||
|
@ -16,11 +16,18 @@ module ProcedureContextConcern
|
|||
|
||||
private
|
||||
|
||||
def stored_procedure_id
|
||||
stored_location = get_stored_location_for(:user)
|
||||
def has_stored_procedure_path?
|
||||
get_stored_location_for(:user)&.start_with?('/commencer/')
|
||||
end
|
||||
|
||||
if stored_location.present? && stored_location.include?('procedure_id=')
|
||||
stored_location.split('procedure_id=').second
|
||||
def find_procedure_in_context
|
||||
uri = URI(get_stored_location_for(:user))
|
||||
path_components = uri.path.split('/')
|
||||
|
||||
if uri.path.start_with?('/commencer/test/')
|
||||
Procedure.brouillon.find_by(path: path_components[3])
|
||||
elsif uri.path.start_with?('/commencer/')
|
||||
Procedure.publiee.find_by(path: path_components[2])
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -38,7 +38,7 @@ module NewUser
|
|||
|
||||
def store_user_location!
|
||||
procedure = Procedure.find_by(path: params[:path])
|
||||
store_location_for(:user, new_dossier_path(procedure_id: procedure.id))
|
||||
store_location_for(:user, commencer_path(path: procedure.path))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ RSpec.describe ProcedureContextConcern, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when no procedure_id is present in the stored return location' do
|
||||
context 'when the stored return location is not a procedure URL' do
|
||||
before do
|
||||
controller.store_location_for(:user, dossiers_path)
|
||||
end
|
||||
|
@ -36,9 +36,9 @@ RSpec.describe ProcedureContextConcern, type: :controller do
|
|||
end
|
||||
|
||||
context 'when a procedure location has been stored' do
|
||||
context 'when the stored procedure does not exist' do
|
||||
context 'when the procedure path does not exist' do
|
||||
before do
|
||||
controller.store_location_for(:user, new_dossier_path(procedure_id: '0'))
|
||||
controller.store_location_for(:user, commencer_path(path: 'non-existent-path'))
|
||||
end
|
||||
|
||||
it 'redirects with an error' do
|
||||
|
@ -47,11 +47,11 @@ RSpec.describe ProcedureContextConcern, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when the stored procedure is not published' do
|
||||
let(:procedure) { create :procedure }
|
||||
context 'when the procedure path exists, but not with the same publication status' do
|
||||
let(:published_procedure) { create :procedure, :published }
|
||||
|
||||
before do
|
||||
controller.store_location_for(:user, new_dossier_path(procedure_id: procedure.id))
|
||||
controller.store_location_for(:user, commencer_test_path(path: published_procedure.path))
|
||||
end
|
||||
|
||||
it 'redirects with an error' do
|
||||
|
@ -60,16 +60,29 @@ RSpec.describe ProcedureContextConcern, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when the stored procedure exists' do
|
||||
let(:procedure) { create :procedure, :published }
|
||||
context 'when the stored procedure is in test' do
|
||||
let(:test_procedure) { create :procedure, :with_path }
|
||||
|
||||
before do
|
||||
controller.store_location_for(:user, new_dossier_path(procedure_id: procedure.id))
|
||||
controller.store_location_for(:user, commencer_test_path(path: test_procedure.path))
|
||||
end
|
||||
|
||||
it 'succeeds, and assigns the procedure on the controller' do
|
||||
expect(subject.status).to eq 200
|
||||
expect(assigns(:procedure)).to eq procedure
|
||||
expect(assigns(:procedure)).to eq test_procedure
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the stored procedure is published' do
|
||||
let(:published_procedure) { create :procedure, :published }
|
||||
|
||||
before do
|
||||
controller.store_location_for(:user, commencer_path(path: published_procedure.path))
|
||||
end
|
||||
|
||||
it 'succeeds, and assigns the procedure on the controller' do
|
||||
expect(subject.status).to eq 200
|
||||
expect(assigns(:procedure)).to eq published_procedure
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -70,7 +70,7 @@ describe NewUser::CommencerController, type: :controller do
|
|||
|
||||
it 'set the path to return after sign-in to the dossier creation path' do
|
||||
subject
|
||||
expect(controller.stored_location_for(:user)).to eq(new_dossier_path(procedure_id: published_procedure.id))
|
||||
expect(controller.stored_location_for(:user)).to eq(commencer_path(path: published_procedure.path))
|
||||
end
|
||||
|
||||
it { expect(subject).to redirect_to(new_user_session_path) }
|
||||
|
@ -81,7 +81,7 @@ describe NewUser::CommencerController, type: :controller do
|
|||
|
||||
it 'set the path to return after sign-up to the dossier creation path' do
|
||||
subject
|
||||
expect(controller.stored_location_for(:user)).to eq(new_dossier_path(procedure_id: published_procedure.id))
|
||||
expect(controller.stored_location_for(:user)).to eq(commencer_path(path: published_procedure.path))
|
||||
end
|
||||
|
||||
it { expect(subject).to redirect_to(new_user_registration_path) }
|
||||
|
|
|
@ -27,7 +27,7 @@ describe Users::RegistrationsController, type: :controller do
|
|||
let(:procedure) { create :procedure, :published }
|
||||
|
||||
before do
|
||||
controller.store_location_for(:user, new_dossier_path(procedure_id: procedure.id))
|
||||
controller.store_location_for(:user, commencer_path(path: procedure.path))
|
||||
end
|
||||
|
||||
it 'makes the saved procedure available' do
|
||||
|
|
|
@ -179,7 +179,7 @@ describe Users::SessionsController, type: :controller do
|
|||
let(:procedure) { create :procedure, :published }
|
||||
|
||||
before do
|
||||
controller.store_location_for(:user, new_dossier_path(procedure_id: procedure.id))
|
||||
controller.store_location_for(:user, commencer_path(path: procedure.path))
|
||||
end
|
||||
|
||||
it 'makes the saved procedure available' do
|
||||
|
|
|
@ -19,6 +19,10 @@ feature 'The gestionnaire part' do
|
|||
expect(page).to have_current_path new_user_session_path
|
||||
sign_in_with(gestionnaire.email, password, true)
|
||||
|
||||
expect(page).to have_current_path(commencer_path(path: procedure.path))
|
||||
click_on 'Commencer la démarche'
|
||||
|
||||
expect(page).to have_content('Identifier votre établissement')
|
||||
expect(page).to have_current_path(siret_dossier_path(procedure.reload.dossiers.last))
|
||||
expect(page).to have_content(procedure.libelle)
|
||||
end
|
||||
|
|
|
@ -133,10 +133,12 @@ feature 'The user' do
|
|||
click_on 'J’ai déjà un compte'
|
||||
|
||||
expect(page).to have_current_path(new_user_session_path)
|
||||
sign_in_with(email, password)
|
||||
|
||||
fill_in 'user_email', with: email
|
||||
fill_in 'user_password', with: password
|
||||
click_on 'Se connecter'
|
||||
expect(page).to have_current_path("/commencer/#{procedure.path}")
|
||||
click_on 'Commencer la démarche'
|
||||
|
||||
expect(page).to have_content("Données d'identité")
|
||||
expect(page).to have_current_path(identite_dossier_path(user_dossier))
|
||||
end
|
||||
|
||||
|
|
|
@ -52,10 +52,12 @@ feature 'linked dropdown lists' do
|
|||
|
||||
expect(page).to have_current_path(new_user_session_path)
|
||||
|
||||
fill_in 'user_email', with: email
|
||||
fill_in 'user_password', with: password
|
||||
click_on 'Se connecter'
|
||||
sign_in_with(email, password)
|
||||
|
||||
expect(page).to have_current_path(commencer_path(path: procedure.path))
|
||||
click_on 'Commencer la démarche'
|
||||
|
||||
expect(page).to have_content("Données d'identité")
|
||||
expect(page).to have_current_path(identite_dossier_path(user_dossier))
|
||||
end
|
||||
|
||||
|
|
|
@ -49,7 +49,11 @@ feature 'Signing up:' do
|
|||
expect(page).to have_content "nous avons besoin de vérifier votre adresse #{user_email}"
|
||||
|
||||
click_confirmation_link_for user_email
|
||||
|
||||
expect(page).to have_current_path(commencer_path(path: procedure.path))
|
||||
expect(page).to have_content 'Votre compte a été activé'
|
||||
click_on 'Commencer la démarche'
|
||||
|
||||
expect(page).to have_current_path identite_dossier_path(procedure.reload.dossiers.last)
|
||||
expect_page_to_have_procedure_description(procedure)
|
||||
end
|
||||
|
|
|
@ -27,6 +27,9 @@ feature 'Signin in:' do
|
|||
|
||||
sign_in_with user.email, password
|
||||
|
||||
expect(page).to have_current_path(commencer_path(path: procedure.path))
|
||||
click_on 'Commencer la démarche'
|
||||
|
||||
expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last)
|
||||
expect_page_to_have_procedure_description(procedure)
|
||||
expect(page).to have_content "Données d'identité"
|
||||
|
|
Loading…
Reference in a new issue