Streamline DossierController#update_brouillon and #update
This commit is contained in:
parent
1341074325
commit
87e59e2bfb
2 changed files with 10 additions and 33 deletions
|
@ -85,8 +85,9 @@ module NewUser
|
|||
end
|
||||
end
|
||||
|
||||
# FIXME: remove PiecesJustificativesService
|
||||
# delegate draft save logic to champ ?
|
||||
# FIXME:
|
||||
# - remove PiecesJustificativesService
|
||||
# - delegate draft save logic to champ ?
|
||||
def update_brouillon
|
||||
@dossier = dossier_with_champs
|
||||
|
||||
|
@ -112,12 +113,8 @@ module NewUser
|
|||
@dossier.en_construction!
|
||||
NotificationMailer.send_initiated_notification(@dossier).deliver_later
|
||||
redirect_to merci_dossier_path(@dossier)
|
||||
elsif current_user.owns?(dossier)
|
||||
if Flipflop.new_dossier_details?
|
||||
redirect_to demande_dossier_path(@dossier)
|
||||
else
|
||||
redirect_to users_dossier_recapitulatif_path(@dossier)
|
||||
end
|
||||
elsif !draft? && !@dossier.can_transition_to_en_construction?
|
||||
render :brouillon
|
||||
else
|
||||
redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user))
|
||||
end
|
||||
|
@ -127,8 +124,8 @@ module NewUser
|
|||
@dossier = dossier_with_champs
|
||||
end
|
||||
|
||||
# FIXME: remove PiecesJustificativesService
|
||||
# delegate draft save logic to champ ?
|
||||
# FIXME:
|
||||
# - remove PiecesJustificativesService
|
||||
def update
|
||||
@dossier = dossier_with_champs
|
||||
|
||||
|
@ -138,22 +135,13 @@ module NewUser
|
|||
errors += @dossier.errors.full_messages
|
||||
end
|
||||
|
||||
if !draft?
|
||||
errors += @dossier.champs.select(&:mandatory_and_blank?)
|
||||
.map { |c| "Le champ #{c.libelle.truncate(200)} doit être rempli." }
|
||||
errors += PiecesJustificativesService.missing_pj_error_messages(@dossier)
|
||||
end
|
||||
errors += @dossier.champs.select(&:mandatory_and_blank?)
|
||||
.map { |c| "Le champ #{c.libelle.truncate(200)} doit être rempli." }
|
||||
errors += PiecesJustificativesService.missing_pj_error_messages(@dossier)
|
||||
|
||||
if errors.present?
|
||||
flash.now.alert = errors
|
||||
render :modifier
|
||||
elsif draft?
|
||||
flash.now.notice = 'Votre brouillon a bien été sauvegardé.'
|
||||
render :modifier
|
||||
elsif @dossier.can_transition_to_en_construction?
|
||||
@dossier.en_construction!
|
||||
NotificationMailer.send_initiated_notification(@dossier).deliver_later
|
||||
redirect_to merci_dossier_path(@dossier)
|
||||
elsif current_user.owns?(dossier)
|
||||
if Flipflop.new_dossier_details?
|
||||
redirect_to demande_dossier_path(@dossier)
|
||||
|
|
|
@ -396,17 +396,6 @@ describe NewUser::DossiersController, type: :controller do
|
|||
it { expect(response).to redirect_to(root_path) }
|
||||
it { expect(flash.alert).to eq("Vous n'avez pas accès à ce dossier") }
|
||||
end
|
||||
|
||||
context 'and the invite updates a dossier en constructions' do
|
||||
before do
|
||||
dossier.en_construction!
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(first_champ.reload.value).to eq('beautiful value') }
|
||||
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction)) }
|
||||
it { expect(response).to redirect_to(users_dossiers_invite_path(invite)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue