fix(commune): should accept postal codes with spaces
This commit is contained in:
parent
38b806a1e0
commit
4a2e499679
2 changed files with 13 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue