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