refactor(spec/services): dynamic procedure reference instead of hardcoded id

This commit is contained in:
Colin Darie 2022-07-19 12:39:36 +02:00
parent a4d9a45280
commit 54181bd920

View file

@ -20,7 +20,7 @@ describe Administrateurs::ServicesController, type: :controller do
horaires: 'horaires',
adresse: 'adresse'
},
procedure_id: 12
procedure_id: procedure.id
}
end
@ -33,7 +33,7 @@ describe Administrateurs::ServicesController, type: :controller do
it { expect(Service.last.telephone).to eq('1234') }
it { expect(Service.last.horaires).to eq('horaires') }
it { expect(Service.last.adresse).to eq('adresse') }
it { expect(response).to redirect_to(admin_services_path(procedure_id: 12)) }
it { expect(response).to redirect_to(admin_services_path(procedure_id: procedure.id)) }
end
context 'when submitting an invalid service' do
@ -113,13 +113,13 @@ describe Administrateurs::ServicesController, type: :controller do
context 'when a service has no related procedure' do
before do
sign_in(admin.user)
delete :destroy, params: { id: service.id, procedure_id: 12 }
delete :destroy, params: { id: service.id, procedure_id: procedure.id }
end
it { expect { service.reload }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect(flash.alert).to be_nil }
it { expect(flash.notice).to eq("#{service.nom} est supprimé") }
it { expect(response).to redirect_to(admin_services_path(procedure_id: 12)) }
it { expect(response).to redirect_to(admin_services_path(procedure_id: procedure.id)) }
end
context 'when a service still has some related procedures' do
@ -127,13 +127,13 @@ describe Administrateurs::ServicesController, type: :controller do
before do
sign_in(admin.user)
delete :destroy, params: { id: service.id, procedure_id: 12 }
delete :destroy, params: { id: service.id, procedure_id: procedure.id }
end
it { expect(service.reload).not_to be_nil }
it { expect(flash.alert).to eq("la démarche #{procedure.libelle} utilise encore le service #{service.nom}. Veuillez l'affecter à un autre service avant de pouvoir le supprimer") }
it { expect(flash.notice).to be_nil }
it { expect(response).to redirect_to(admin_services_path(procedure_id: 12)) }
it { expect(response).to redirect_to(admin_services_path(procedure_id: procedure.id)) }
end
context "when a service has some related discarded procedures" do