Merge pull request #2278 from betagouv/fix-2277
[Fix #2277] Do not crash when creating a service with invalid data
This commit is contained in:
commit
1cf3678b63
2 changed files with 6 additions and 3 deletions
|
@ -17,6 +17,7 @@ module NewAdministrateur
|
|||
redirect_to services_path(procedure_id: params[:procedure_id]),
|
||||
notice: "#{new_service.nom} créé"
|
||||
else
|
||||
@procedure = procedure
|
||||
flash[:alert] = new_service.errors.full_messages
|
||||
render :new
|
||||
end
|
||||
|
@ -34,6 +35,7 @@ module NewAdministrateur
|
|||
redirect_to services_path(procedure_id: params[:procedure_id]),
|
||||
notice: "#{@service.nom} modifié"
|
||||
else
|
||||
@procedure = procedure
|
||||
flash[:alert] = @service.errors.full_messages
|
||||
render :edit
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
describe NewAdministrateur::ServicesController, type: :controller do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:procedure) { create(:procedure, administrateur: admin) }
|
||||
|
||||
describe '#create' do
|
||||
before do
|
||||
|
@ -38,7 +39,7 @@ describe NewAdministrateur::ServicesController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when submitting an invalid service' do
|
||||
let(:params) { { service: { nom: 'super service' } } }
|
||||
let(:params) { { service: { nom: 'super service' }, procedure_id: procedure.id } }
|
||||
|
||||
it { expect(flash.alert).not_to be_nil }
|
||||
it { expect(response).to render_template(:new) }
|
||||
|
@ -54,7 +55,7 @@ describe NewAdministrateur::ServicesController, type: :controller do
|
|||
params = {
|
||||
id: service.id,
|
||||
service: service_params,
|
||||
procedure_id: 12
|
||||
procedure_id: procedure.id
|
||||
}
|
||||
patch :update, params: params
|
||||
end
|
||||
|
@ -64,7 +65,7 @@ describe NewAdministrateur::ServicesController, type: :controller do
|
|||
it { expect(flash.notice).to eq('nom modifié') }
|
||||
it { expect(Service.last.nom).to eq('nom') }
|
||||
it { expect(Service.last.type_organisme).to eq('region') }
|
||||
it { expect(response).to redirect_to(services_path(procedure_id: 12)) }
|
||||
it { expect(response).to redirect_to(services_path(procedure_id: procedure.id)) }
|
||||
end
|
||||
|
||||
context 'when updating a service with invalid data' do
|
||||
|
|
Loading…
Reference in a new issue