diff --git a/app/controllers/new_administrateur/services_controller.rb b/app/controllers/new_administrateur/services_controller.rb index 9e5d682a4..a969da1b3 100644 --- a/app/controllers/new_administrateur/services_controller.rb +++ b/app/controllers/new_administrateur/services_controller.rb @@ -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 diff --git a/spec/controllers/new_administrateur/services_controller_spec.rb b/spec/controllers/new_administrateur/services_controller_spec.rb index 8bf213f79..3a2c4866b 100644 --- a/spec/controllers/new_administrateur/services_controller_spec.rb +++ b/spec/controllers/new_administrateur/services_controller_spec.rb @@ -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