fix(conditional): don't .to_i/to_f => 0 an invalid number

This commit is contained in:
Colin Darie 2023-09-26 10:38:38 +02:00
parent aac7de208f
commit 123114be81
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
3 changed files with 16 additions and 0 deletions

View file

@ -18,6 +18,8 @@ class Champs::DecimalNumberChamp < Champ
private
def processed_value
return if invalid?
value&.to_f
end
end

View file

@ -20,6 +20,8 @@ class Champs::IntegerNumberChamp < Champ
private
def processed_value
return if invalid?
value&.to_i
end
end

View file

@ -39,6 +39,12 @@ describe Logic::ChampValue do
it { is_expected.to be nil }
end
context 'with invalid value' do
before { champ.value = 'environ 300' }
it { is_expected.to be nil }
end
end
context 'decimal tdc' do
@ -46,6 +52,12 @@ describe Logic::ChampValue do
it { expect(champ_value(champ.stable_id).type([champ.type_de_champ])).to eq(:number) }
it { is_expected.to eq(42.01) }
context 'with invalid value' do
before { champ.value = 'racine de 2' }
it { is_expected.to be nil }
end
end
context 'dropdown tdc' do