Skip to content

Commit

Permalink
Supprime les espaces éventuellement saisis dans le SIRET
Browse files Browse the repository at this point in the history
  • Loading branch information
etienneCharignon committed Nov 13, 2024
1 parent fdb8a49 commit 02743e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/models/structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Structure < ApplicationRecord
end
end

before_validation :retire_espaces_siret
after_validation :geocode, if: ->(s) { s.code_postal.present? and s.code_postal_changed? }
after_create :programme_email_relance

Expand Down Expand Up @@ -90,4 +91,10 @@ def verifie_siret_ou_siren

errors.add(:siret, :invalid)
end

def retire_espaces_siret
return if siret.blank?

self.siret = siret.gsub(/[[:space:]]/, '')
end
end
11 changes: 11 additions & 0 deletions spec/models/structure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ def mock_geo_api(departement, code_region, region)
it { expect(structure.errors[:siret]).to be_blank }
end

context 'quand il est un siret valide avec des espaces' do
let(:structure) { build :structure, siret: '1234567890 1234' }

before { structure.valid? }

it do
expect(structure.errors[:siret]).to be_blank
expect(structure.siret).to eq('12345678901234')
end
end

context 'quand il est un siret valide (14 chiffres)' do
let(:structure) { build :structure, siret: '12345678901234' }

Expand Down

0 comments on commit 02743e4

Please sign in to comment.