Fix number champs validation

This commit is contained in:
Paul Chavard 2018-11-29 14:35:42 +01:00
parent 034b3f600b
commit ca147969ab
4 changed files with 26 additions and 2 deletions

View file

@ -1,5 +1,5 @@
class Champs::DecimalNumberChamp < Champ
validates :value, numericality: { allow_nil: true }
validates :value, numericality: { allow_nil: true, allow_blank: true }
def value_for_export
value.to_f

View file

@ -1,5 +1,5 @@
class Champs::IntegerNumberChamp < Champ
validates :value, numericality: { only_integer: true, allow_nil: true }
validates :value, numericality: { only_integer: true, allow_nil: true, allow_blank: true }
def value_for_export
value.to_i

View file

@ -21,5 +21,17 @@ describe Champs::DecimalNumberChamp do
it { is_expected.to_not be_valid }
end
context 'when the value is blank' do
let(:value) { '' }
it { is_expected.to be_valid }
end
context 'when the value is nil' do
let(:value) { nil }
it { is_expected.to be_valid }
end
end
end

View file

@ -21,5 +21,17 @@ describe Champs::IntegerNumberChamp do
it { is_expected.to_not be_valid }
end
context 'when the value is blank' do
let(:value) { '' }
it { is_expected.to be_valid }
end
context 'when the value is nil' do
let(:value) { nil }
it { is_expected.to be_valid }
end
end
end