From e9b5c4a61599b177860e16bb29107772e2dbad82 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Fri, 20 Sep 2024 15:21:22 +0200 Subject: [PATCH] [#10837] Add an explicit message when SIRET is not valid on service --- app/models/procedure.rb | 4 ++-- app/models/service.rb | 1 + .../administrateurs/procedures/publication.html.haml | 4 ++-- spec/models/service_spec.rb | 9 +++++++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index a67fa05ef..464916e16 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -674,7 +674,7 @@ class Procedure < ApplicationRecord result << :service end - if service_test? + if service_siret_test? result << :service end @@ -710,7 +710,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) }