Service: can update a service

This commit is contained in:
Frederic Merizen 2018-04-19 18:12:48 +02:00 committed by simon lehericey
parent c54c85bad8
commit 365cb9b44d
7 changed files with 70 additions and 4 deletions

View file

@ -24,4 +24,29 @@ describe NewAdministrateur::ServicesController, type: :controller do
it { expect(response).to render_template(:new) }
end
end
describe '#update' do
let!(:service) { create(:service, administrateur: admin) }
let(:service_params) { { nom: 'nom', type_organisme: 'region' } }
before do
sign_in admin
patch :update, params: { id: service.id, service: service_params }
end
context 'when updating a service' do
it { expect(flash.alert).to be_nil }
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) }
end
context 'when updating a service with invalid data' do
let(:service_params) { { nom: '', type_organisme: 'region' } }
it { expect(flash.alert).not_to be_nil }
it { expect(response).to render_template(:edit) }
end
end
end