Merge pull request #2928 from betagouv/fix-2276
Fix 2276 Quand on créé un service avec de la donnée invalide, on perd tout ce qu'on a entré dans le formulaire
This commit is contained in:
commit
430c58a2ea
3 changed files with 8 additions and 6 deletions
|
@ -7,18 +7,19 @@ module NewAdministrateur
|
|||
|
||||
def new
|
||||
@procedure = procedure
|
||||
@service = Service.new
|
||||
end
|
||||
|
||||
def create
|
||||
new_service = Service.new(service_params)
|
||||
new_service.administrateur = current_administrateur
|
||||
@service = Service.new(service_params)
|
||||
@service.administrateur = current_administrateur
|
||||
|
||||
if new_service.save
|
||||
if @service.save
|
||||
redirect_to services_path(procedure_id: params[:procedure_id]),
|
||||
notice: "#{new_service.nom} créé"
|
||||
notice: "#{@service.nom} créé"
|
||||
else
|
||||
@procedure = procedure
|
||||
flash[:alert] = new_service.errors.full_messages
|
||||
flash[:alert] = @service.errors.full_messages
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,4 +8,4 @@
|
|||
%h1 Nouveau Service
|
||||
|
||||
= render partial: 'form',
|
||||
locals: { service: Service.new, procedure_id: @procedure.id }
|
||||
locals: { service: @service, procedure_id: @procedure.id }
|
||||
|
|
|
@ -43,6 +43,7 @@ describe NewAdministrateur::ServicesController, type: :controller do
|
|||
|
||||
it { expect(flash.alert).not_to be_nil }
|
||||
it { expect(response).to render_template(:new) }
|
||||
it { expect(assigns(:service).nom).to eq('super service') }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue