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:
Mathieu Magnin 2018-10-30 15:57:40 +01:00 committed by GitHub
commit 430c58a2ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View file

@ -7,18 +7,19 @@ module NewAdministrateur
def new def new
@procedure = procedure @procedure = procedure
@service = Service.new
end end
def create def create
new_service = Service.new(service_params) @service = Service.new(service_params)
new_service.administrateur = current_administrateur @service.administrateur = current_administrateur
if new_service.save if @service.save
redirect_to services_path(procedure_id: params[:procedure_id]), redirect_to services_path(procedure_id: params[:procedure_id]),
notice: "#{new_service.nom} créé" notice: "#{@service.nom} créé"
else else
@procedure = procedure @procedure = procedure
flash[:alert] = new_service.errors.full_messages flash[:alert] = @service.errors.full_messages
render :new render :new
end end
end end

View file

@ -8,4 +8,4 @@
%h1 Nouveau Service %h1 Nouveau Service
= render partial: 'form', = render partial: 'form',
locals: { service: Service.new, procedure_id: @procedure.id } locals: { service: @service, procedure_id: @procedure.id }

View file

@ -43,6 +43,7 @@ describe NewAdministrateur::ServicesController, type: :controller do
it { expect(flash.alert).not_to be_nil } it { expect(flash.alert).not_to be_nil }
it { expect(response).to render_template(:new) } it { expect(response).to render_template(:new) }
it { expect(assigns(:service).nom).to eq('super service') }
end end
end end