Merge pull request #3090 from tchak/fix-number-champs-validation

Fix number champs validation
This commit is contained in:
Paul Chavard 2018-11-29 15:21:25 +01:00 committed by GitHub
commit f51f68ec03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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