Merge pull request #1125 from sgmap/fix-1011

[Fix #1011] Change the “Enregistrer un brouillon” button behaviour
This commit is contained in:
gregoirenovel 2017-12-21 16:46:00 +01:00 committed by GitHub
commit d45724c1af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 15 deletions

View file

@ -39,7 +39,7 @@ class Users::DescriptionController < UsersController
errors_upload = PiecesJustificativesService.upload!(dossier, current_user, params)
return redirect_to_description_with_errors(dossier, errors_upload) if errors_upload.any?
if params[:champs] && !brouillon_submission?
if params[:champs] && !(brouillon_submission? || brouillon_then_dashboard_submission?)
errors =
ChampsService.build_error_messages(dossier.champs) +
PiecesJustificativesService.missing_pj_error_messages(dossier)
@ -48,6 +48,8 @@ class Users::DescriptionController < UsersController
if brouillon_submission?
flash.notice = 'Votre brouillon a bien été sauvegardé.'
redirect_to users_dossier_description_path(dossier.id)
elsif brouillon_then_dashboard_submission?
redirect_to url_for(controller: :dossiers, action: :index, liste: :brouillon)
else
if dossier.brouillon?
@ -110,7 +112,11 @@ class Users::DescriptionController < UsersController
end
def brouillon_submission?
params[:submit] && params[:submit].keys.first == 'brouillon'
params[:submit] && params[:submit]['brouillon'].present?
end
def brouillon_then_dashboard_submission?
params[:submit] && params[:submit]['brouillon_then_dashboard'].present?
end
def check_autorisation_donnees

View file

@ -44,3 +44,4 @@
- else
= submit_tag 'Soumettre mon dossier', id: 'suivant', name: 'submit[nouveaux]', class: 'btn btn btn-success', style: 'float: right;', disabled: @procedure.archivee?, data: { disable_with: 'Soumettre votre dossier', submit: true }
= submit_tag 'Enregistrer un brouillon', id: 'brouillon', name: 'submit[brouillon]', class: 'btn btn-xs btn-default', style: 'float: right; margin-right: 10px; margin-top: 6px;', disabled: @procedure.archivee?, data: { disable_with: 'Enregistrer un brouillon', submit: true }
= submit_tag "Enregistrer et voir mes dossiers", id: 'brouillon_then_dashboard', name: 'submit[brouillon_then_dashboard]', class: 'btn btn-xs btn-default', style: 'float: right; margin-right: 10px; margin-top: 6px;', disabled: @procedure.archivee?, data: { disable_with: 'Voir mes brouillons et dossiers', submit: true }

View file

@ -110,8 +110,6 @@ shared_examples 'description_controller_spec' do
context 'Tous les attributs sont bons' do
describe 'Premier enregistrement des données' do
let(:submit) { {nouveaux: 'nouveaux'} }
subject { post :update, params: {dossier_id: dossier_id, submit: submit} }
before do
@ -120,22 +118,38 @@ shared_examples 'description_controller_spec' do
dossier.reload
end
it "redirection vers la page recapitulative" do
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
end
it 'etat du dossier est soumis' do
expect(dossier.state).to eq('en_construction')
end
context 'when user whould like save just a brouillon' do
let(:submit) { {brouillon: 'brouillon'} }
context "when the user submits the dossier" do
let(:submit) { {nouveaux: 'nouveaux'} }
it "redirection vers la page recapitulative" do
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
end
it 'etat du dossier est en construction' do
expect(dossier.state).to eq('en_construction')
end
end
context 'when user saves a brouillon' do
let(:submit) { {brouillon: 'brouillon'} }
it "reste sur la page du dossier" do
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/description")
end
it 'etat du dossier est brouillon' do
expect(dossier.state).to eq('brouillon')
end
end
context 'when user saves a brouillon and goes to dashboard' do
let(:submit) { {brouillon_then_dashboard: 'brouillon_then_dashboard'} }
it "goes to dashboard" do
expect(response).to redirect_to("/users/dossiers?liste=brouillon")
end
it 'etat du dossier est soumis' do
it 'etat du dossier est brouillon' do
expect(dossier.state).to eq('brouillon')
end
end