Use enum to the fullest with Service.type_organismes

This commit is contained in:
gregoirenovel 2018-08-28 12:28:05 +02:00
parent 2d3b553e4d
commit ee25bba38c
3 changed files with 6 additions and 6 deletions

View file

@ -30,7 +30,7 @@ describe NewAdministrateur::ServicesController, type: :controller do
it { expect(Service.last.nom).to eq('super service') }
it { expect(Service.last.organisme).to eq('organisme') }
it { expect(Service.last.siret).to eq('01234567891234') }
it { expect(Service.last.type_organisme).to eq('region') }
it { expect(Service.last.type_organisme).to eq(Service.type_organismes.fetch(:region)) }
it { expect(Service.last.email).to eq('email@toto.com') }
it { expect(Service.last.telephone).to eq('1234') }
it { expect(Service.last.horaires).to eq('horaires') }
@ -48,7 +48,7 @@ describe NewAdministrateur::ServicesController, type: :controller do
describe '#update' do
let!(:service) { create(:service, administrateur: admin) }
let(:service_params) { { nom: 'nom', type_organisme: 'region' } }
let(:service_params) { { nom: 'nom', type_organisme: Service.type_organismes.fetch(:region) } }
before do
sign_in admin
@ -64,12 +64,12 @@ describe NewAdministrateur::ServicesController, type: :controller 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(Service.last.type_organisme).to eq(Service.type_organismes.fetch(:region)) }
it { expect(response).to redirect_to(services_path(procedure_id: procedure.id)) }
end
context 'when updating a service with invalid data' do
let(:service_params) { { nom: '', type_organisme: 'region' } }
let(:service_params) { { nom: '', type_organisme: Service.type_organismes.fetch(:region) } }
it { expect(flash.alert).not_to be_nil }
it { expect(response).to render_template(:edit) }

View file

@ -2,7 +2,7 @@ FactoryBot.define do
factory :service do
nom 'service'
organisme 'organisme'
type_organisme 'commune'
type_organisme Service.type_organismes.fetch(:commune)
administrateur { create(:administrateur) }
email 'email@toto.com'
telephone '1234'

View file

@ -5,7 +5,7 @@ describe Service, type: :model do
{
nom: 'service des jardins',
organisme: 'mairie des iles',
type_organisme: 'commune',
type_organisme: Service.type_organismes.fetch(:commune),
email: 'super@email.com',
telephone: '1212202',
horaires: 'du lundi au vendredi',