diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 14c489861..168c486ec 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -653,7 +653,7 @@ class Procedure < ApplicationRecord result << :service end - if service_test? + if service_siret_test? result << :service end @@ -689,7 +689,7 @@ class Procedure < ApplicationRecord end end - def service_test? + def service_siret_test? service&.siret == Service::SIRET_TEST end diff --git a/app/models/service.rb b/app/models/service.rb index 78f15b777..67d6ac761 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -22,6 +22,7 @@ class Service < ApplicationRecord validates :nom, uniqueness: { scope: :administrateur, message: 'existe déjà' } validates :organisme, presence: { message: 'doit être renseigné' }, allow_nil: false validates :siret, siret_format: true + validates :siret, comparison: { other_than: SIRET_TEST, message: "n'est pas valide" }, on: :update validates :type_organisme, presence: { message: 'doit être renseigné' }, allow_nil: false validates :email, presence: { message: 'doit être renseigné' }, allow_nil: false validates :telephone, phone: { possible: true, allow_blank: true } diff --git a/app/views/administrateurs/procedures/publication.html.haml b/app/views/administrateurs/procedures/publication.html.haml index 6549a22fd..9248dc2b6 100644 --- a/app/views/administrateurs/procedures/publication.html.haml +++ b/app/views/administrateurs/procedures/publication.html.haml @@ -46,8 +46,8 @@ %li= link_to("des instructeurs", admin_procedure_groupe_instructeur_path(@procedure, @procedure.defaut_groupe_instructeur)) - if @procedure.service.nil? %li= link_to("un service", admin_services_path(procedure_id: @procedure)) - - if @procedure.service_test? - %li= link_to("un service valide", admin_services_path(procedure_id: @procedure)) + - if @procedure.service_siret_test? + %li= link_to("un service avec un SIRET valide", admin_services_path(procedure_id: @procedure)) = link_to t('.back_to_procedure'), admin_procedure_path(id: @procedure), class: 'fr-btn fr-btn--secondary fr-btn--icon-left fr-icon-arrow-go-back-line fr-mt-2w' - else diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 74b6cad79..decd6e07d 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -89,6 +89,15 @@ describe Service, type: :model do end end + describe 'validation on update' do + subject { create(:service) } + + it 'should not allow to have a test siret' do + subject.siret = Service::SIRET_TEST + expect(subject).not_to be_valid + end + end + describe "etablissement adresse & geo coordinates" do subject { create(:service, etablissement_lat: latitude, etablissement_lng: longitude, etablissement_infos: etablissement_infos) }