Merge pull request #8930 from tchak/fix-champ-commune-spaces

ETQ usager, je voudrai pouvoir remplir un code postal avec des espaces
This commit is contained in:
Paul Chavard 2023-04-20 08:40:38 +00:00 committed by GitHub
commit 88f680a265
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

@ -52,6 +52,10 @@ class Champs::CommuneChamp < Champs::TextChamp
code_postal.present?
end
def code_postal=(value)
super(value&.gsub(/[[:space:]]/, ''))
end
alias postal_code code_postal
def name

View file

@ -2,10 +2,9 @@ describe Champs::CommuneChamp do
let(:code_insee) { '63102' }
let(:code_postal) { '63290' }
let(:code_departement) { '63' }
let(:champ) { create(:champ_communes, code_postal: code_postal) }
describe 'value' do
let(:champ) { create(:champ_communes, code_postal: code_postal) }
it 'with code_postal' do
champ.update(value: code_insee)
expect(champ.to_s).to eq('Châteldon (63290)')
@ -18,4 +17,12 @@ describe Champs::CommuneChamp do
expect(champ.communes.size).to eq(8)
end
end
describe 'code_postal with spaces' do
let(:code_postal) { ' 63 2 90  ' }
it 'with code_postal' do
expect(champ.communes.size).to eq(8)
end
end
end