dossiers: save draft by default (instead of submitting)
Make the default behavior of `update_brouillon` be to update the draft, instead of submitting the dossier. This makes all requests made to `update_brouillon` without specifying an extra `submit_draft` parameter to just save the draft. It will make autosaving the draft easier and safer.
This commit is contained in:
parent
03a7bc3d5a
commit
8b8a96abda
3 changed files with 16 additions and 15 deletions
|
@ -147,13 +147,13 @@ module Users
|
|||
flash.now.alert = errors
|
||||
render :brouillon
|
||||
else
|
||||
if save_draft?
|
||||
flash.now.notice = 'Votre brouillon a bien été sauvegardé.'
|
||||
render :brouillon
|
||||
else
|
||||
if passage_en_construction?
|
||||
@dossier.en_construction!
|
||||
NotificationMailer.send_initiated_notification(@dossier).deliver_later
|
||||
redirect_to merci_dossier_path(@dossier)
|
||||
else
|
||||
flash.now.notice = 'Votre brouillon a bien été sauvegardé.'
|
||||
render :brouillon
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -368,7 +368,7 @@ module Users
|
|||
end
|
||||
|
||||
def save_draft?
|
||||
dossier.brouillon? && params[:save_draft]
|
||||
dossier.brouillon? && !params[:submit_draft]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,13 +43,14 @@
|
|||
- if dossier.brouillon?
|
||||
= f.button 'Enregistrer le brouillon',
|
||||
formnovalidate: true,
|
||||
name: :save_draft,
|
||||
value: true,
|
||||
class: 'button send secondary',
|
||||
data: { 'disable-with': "Envoi en cours…" }
|
||||
|
||||
- if dossier.can_transition_to_en_construction?
|
||||
= f.button 'Déposer le dossier',
|
||||
name: :submit_draft,
|
||||
value: true,
|
||||
class: 'button send primary',
|
||||
disabled: !current_user.owns?(dossier),
|
||||
data: { 'disable-with': "Envoi en cours…" }
|
||||
|
|
|
@ -100,38 +100,38 @@ describe Users::DossiersController, type: :controller do
|
|||
let(:user) { create(:user) }
|
||||
let(:asked_dossier) { create(:dossier) }
|
||||
let(:ensure_authorized) { :forbid_invite_submission! }
|
||||
let(:draft) { false }
|
||||
let(:submit) { true }
|
||||
|
||||
before do
|
||||
@controller.params = @controller.params.merge(dossier_id: asked_dossier.id, save_draft: draft)
|
||||
@controller.params = @controller.params.merge(dossier_id: asked_dossier.id, submit_draft: submit)
|
||||
allow(@controller).to receive(:current_user).and_return(user)
|
||||
allow(@controller).to receive(:redirect_to)
|
||||
end
|
||||
|
||||
context 'when a user save their own draft' do
|
||||
let(:asked_dossier) { create(:dossier, user: user) }
|
||||
let(:draft) { true }
|
||||
let(:submit) { false }
|
||||
|
||||
it_behaves_like 'does not redirect nor flash'
|
||||
end
|
||||
|
||||
context 'when a user submit their own dossier' do
|
||||
let(:asked_dossier) { create(:dossier, user: user) }
|
||||
let(:draft) { false }
|
||||
let(:submit) { true }
|
||||
|
||||
it_behaves_like 'does not redirect nor flash'
|
||||
end
|
||||
|
||||
context 'when an invite save the draft for a dossier where they where invited' do
|
||||
before { create(:invite, dossier: asked_dossier, user: user) }
|
||||
let(:draft) { true }
|
||||
let(:submit) { false }
|
||||
|
||||
it_behaves_like 'does not redirect nor flash'
|
||||
end
|
||||
|
||||
context 'when an invite submit a dossier where they where invited' do
|
||||
before { create(:invite, dossier: asked_dossier, user: user) }
|
||||
let(:draft) { false }
|
||||
let(:submit) { true }
|
||||
|
||||
it_behaves_like 'redirects and flashes'
|
||||
end
|
||||
|
@ -394,7 +394,7 @@ describe Users::DossiersController, type: :controller do
|
|||
}
|
||||
}
|
||||
end
|
||||
let(:payload) { submit_payload }
|
||||
let(:payload) { submit_payload.merge(submit_draft: true) }
|
||||
|
||||
subject do
|
||||
Timecop.freeze(now) do
|
||||
|
@ -480,7 +480,7 @@ describe Users::DossiersController, type: :controller do
|
|||
it { expect(flash.alert).to eq(['Le champ l doit être rempli.']) }
|
||||
|
||||
context 'and the user saves a draft' do
|
||||
let(:payload) { submit_payload.merge(save_draft: true) }
|
||||
let(:payload) { submit_payload.except(:submit_draft) }
|
||||
|
||||
it { expect(response).to render_template(:brouillon) }
|
||||
it { expect(flash.notice).to eq('Votre brouillon a bien été sauvegardé.') }
|
||||
|
@ -510,7 +510,7 @@ describe Users::DossiersController, type: :controller do
|
|||
let!(:invite) { create(:invite, dossier: dossier, user: user) }
|
||||
|
||||
context 'and the invite saves a draft' do
|
||||
let(:payload) { submit_payload.merge(save_draft: true) }
|
||||
let(:payload) { submit_payload.except(:submit_draft) }
|
||||
|
||||
before do
|
||||
first_champ.type_de_champ.update(mandatory: true, libelle: 'l')
|
||||
|
|
Loading…
Reference in a new issue