fix(conditional): don't .to_i/to_f => 0 an invalid number
This commit is contained in:
parent
aac7de208f
commit
123114be81
3 changed files with 16 additions and 0 deletions
|
@ -18,6 +18,8 @@ class Champs::DecimalNumberChamp < Champ
|
|||
private
|
||||
|
||||
def processed_value
|
||||
return if invalid?
|
||||
|
||||
value&.to_f
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,6 +20,8 @@ class Champs::IntegerNumberChamp < Champ
|
|||
private
|
||||
|
||||
def processed_value
|
||||
return if invalid?
|
||||
|
||||
value&.to_i
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue