Merge pull request #10587 from tchak/refactor-no-validate-on-format

refactor(champ): remove call to validation from value formatting code
This commit is contained in:
mfo 2024-07-09 14:31:10 +00:00 committed by GitHub
commit f3690d8890
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 4 additions and 27 deletions

View file

@ -107,11 +107,6 @@ class Champ < ApplicationRecord
[to_s]
end
def valid_value
return unless valid_champ_value?
value
end
def to_s
TypeDeChamp.champ_value(type_champ, self)
end

View file

@ -20,7 +20,7 @@ class TypesDeChamp::DecimalNumberTypeDeChamp < TypesDeChamp::TypeDeChampBase
private
def champ_formatted_value(champ)
champ.valid_value&.to_f
champ.value&.to_f
end
end
end

View file

@ -20,7 +20,7 @@ class TypesDeChamp::IntegerNumberTypeDeChamp < TypesDeChamp::TypeDeChampBase
private
def champ_formatted_value(champ)
champ.valid_value&.to_i
champ.value&.to_i
end
end
end

View file

@ -66,12 +66,12 @@ class TypesDeChamp::TypeDeChampBase
when 2
champ_value(champ)
else
champ.valid_value.presence || champ_default_api_value(version)
champ.value.presence || champ_default_api_value(version)
end
end
def champ_value_for_export(champ, path = :value)
path == :value ? champ.valid_value.presence : champ_default_export_value(path)
path == :value ? champ.value.presence : champ_default_export_value(path)
end
def champ_value_for_tag(champ, path = :value)

View file

@ -40,12 +40,6 @@ 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
@ -53,18 +47,6 @@ 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 with too many digits after the decimal point' do
before { champ.value = '42.1234' }
it { is_expected.to be nil }
end
context 'with invalid value' do
before { champ.value = 'racine de 2' }
it { is_expected.to be nil }
end
end
context 'dropdown tdc' do