models: stop truncating DROM phone numbers

Fix #6996
This commit is contained in:
Pierre de La Morinerie 2022-03-01 16:44:16 +01:00 committed by Paul Chavard
parent 5150e33212
commit f35d18cd5c
2 changed files with 16 additions and 3 deletions

View file

@ -49,6 +49,7 @@ class Champs::PhoneChamp < Champs::TextChamp
}, unless: -> { Phonelib.valid_for_countries?(value, DEFAULT_COUNTRY_CODES) }
def to_s
value.present? ? Phonelib.parse(value).full_national : ''
return '' if value.blank?
Phonelib.parse_for_countries(value, DEFAULT_COUNTRY_CODES).full_national
end
end

View file

@ -40,9 +40,21 @@ describe Champs::PhoneChamp do
expect(champ_with_value("88473500")).to be_valid
expect(champ_with_value("89473500")).to be_valid
end
end
def champ_with_value(number)
phone_champ.tap { |c| c.value = number }
describe '#to_s' do
context 'for valid phone numbers' do
it 'returns the national part of the number, formatted nicely' do
expect(champ_with_value("0115789055").to_s).to eq("01 15 78 90 55")
expect(champ_with_value("+33115789055").to_s).to eq("01 15 78 90 55")
# DROM phone numbers are formatted differently but still formatted
expect(champ_with_value("0696047807").to_s).to eq("0696 04 78 07")
expect(champ_with_value("45187272").to_s).to eq("45187272")
end
end
end
def champ_with_value(number)
phone_champ.tap { |c| c.value = number }
end
end