Service: keep procedure_id
This commit is contained in:
parent
a8f2528dcd
commit
5d7455f436
6 changed files with 28 additions and 10 deletions
|
@ -12,7 +12,8 @@ module NewAdministrateur
|
|||
new_service.administrateur = current_administrateur
|
||||
|
||||
if new_service.save
|
||||
redirect_to services_path, notice: "#{new_service.nom} créé"
|
||||
redirect_to services_path(procedure_id: params[:procedure_id]),
|
||||
notice: "#{new_service.nom} créé"
|
||||
else
|
||||
flash[:alert] = new_service.errors.full_messages
|
||||
render :new
|
||||
|
@ -27,7 +28,8 @@ module NewAdministrateur
|
|||
@service = service
|
||||
|
||||
if @service.update(service_params)
|
||||
redirect_to services_path, notice: "#{@service.nom} modifié"
|
||||
redirect_to services_path(procedure_id: params[:procedure_id]),
|
||||
notice: "#{@service.nom} modifié"
|
||||
else
|
||||
flash[:alert] = @service.errors.full_messages
|
||||
render :edit
|
||||
|
|
|
@ -11,5 +11,8 @@
|
|||
|
||||
= f.select :type_organisme, Service.type_organismes.keys.map { |key| [ I18n.t("type_organisme.#{key}"), key] }
|
||||
|
||||
- if procedure_id.present?
|
||||
= hidden_field_tag :procedure_id, procedure_id
|
||||
|
||||
.send-wrapper
|
||||
= f.submit "Valider", class: 'button send'
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
%h1 Modifier le service
|
||||
|
||||
= render partial: 'form',
|
||||
locals: { service: @service }
|
||||
locals: { service: @service, procedure_id: params[:procedure_id] }
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
%th
|
||||
nom
|
||||
%th.change
|
||||
= link_to('Nouveau service', new_service_path, class: 'button')
|
||||
= link_to('Nouveau service', new_service_path(procedure_id: params[:procedure_id]), class: 'button')
|
||||
|
||||
%tbody
|
||||
- @services.each do |service|
|
||||
|
@ -15,4 +15,4 @@
|
|||
%td
|
||||
= service.nom
|
||||
%td.change
|
||||
= link_to('modifier', edit_service_path(service))
|
||||
= link_to('modifier', edit_service_path(service, procedure_id: params[:procedure_id]))
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
%h1 Nouveau Service
|
||||
|
||||
= render partial: 'form',
|
||||
locals: { service: Service.new }
|
||||
locals: { service: Service.new, procedure_id: params[:procedure_id] }
|
||||
|
|
|
@ -8,13 +8,21 @@ describe NewAdministrateur::ServicesController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when submitting a new service' do
|
||||
let(:params) { { service: { nom: 'super service', type_organisme: 'region' } } }
|
||||
let(:params) do
|
||||
{
|
||||
service: {
|
||||
nom: 'super service',
|
||||
type_organisme: 'region'
|
||||
},
|
||||
procedure_id: 12
|
||||
}
|
||||
end
|
||||
|
||||
it { expect(flash.alert).to be_nil }
|
||||
it { expect(flash.notice).to eq('super service créé') }
|
||||
it { expect(Service.last.nom).to eq('super service') }
|
||||
it { expect(Service.last.type_organisme).to eq('region') }
|
||||
it { expect(response).to redirect_to(services_path) }
|
||||
it { expect(response).to redirect_to(services_path(procedure_id: 12)) }
|
||||
end
|
||||
|
||||
context 'when submitting an invalid service' do
|
||||
|
@ -31,7 +39,12 @@ describe NewAdministrateur::ServicesController, type: :controller do
|
|||
|
||||
before do
|
||||
sign_in admin
|
||||
patch :update, params: { id: service.id, service: service_params }
|
||||
params = {
|
||||
id: service.id,
|
||||
service: service_params,
|
||||
procedure_id: 12
|
||||
}
|
||||
patch :update, params: params
|
||||
end
|
||||
|
||||
context 'when updating a service' do
|
||||
|
@ -39,7 +52,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) }
|
||||
it { expect(response).to redirect_to(services_path(procedure_id: 12)) }
|
||||
end
|
||||
|
||||
context 'when updating a service with invalid data' do
|
||||
|
|
Loading…
Add table
Reference in a new issue