diff --git a/app/models/champs/decimal_number_champ.rb b/app/models/champs/decimal_number_champ.rb index dcfcea707..b22fb2379 100644 --- a/app/models/champs/decimal_number_champ.rb +++ b/app/models/champs/decimal_number_champ.rb @@ -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 diff --git a/app/models/champs/integer_number_champ.rb b/app/models/champs/integer_number_champ.rb index d1e82ec4a..d7ca399a7 100644 --- a/app/models/champs/integer_number_champ.rb +++ b/app/models/champs/integer_number_champ.rb @@ -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 diff --git a/spec/models/champs/decimal_number_champ_spec.rb b/spec/models/champs/decimal_number_champ_spec.rb index 3e3bb9c26..8ec0ebdaf 100644 --- a/spec/models/champs/decimal_number_champ_spec.rb +++ b/spec/models/champs/decimal_number_champ_spec.rb @@ -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 diff --git a/spec/models/champs/integer_number_champ_spec.rb b/spec/models/champs/integer_number_champ_spec.rb index 957d5e5c6..6a7152759 100644 --- a/spec/models/champs/integer_number_champ_spec.rb +++ b/spec/models/champs/integer_number_champ_spec.rb @@ -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