2018-10-31 19:48:28 +01:00
|
|
|
describe Champs::IntegerNumberChamp do
|
2019-07-10 13:27:36 +02:00
|
|
|
subject { build(:champ_integer_number, value: value).tap(&:valid?) }
|
2018-10-31 19:48:28 +01:00
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
context 'when the value is integer number' do
|
|
|
|
let(:value) { 2 }
|
|
|
|
|
|
|
|
it { is_expected.to be_valid }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the value is decimal number' do
|
|
|
|
let(:value) { 2.6 }
|
|
|
|
|
|
|
|
it { is_expected.to_not be_valid }
|
2019-07-10 13:27:36 +02:00
|
|
|
it { expect(subject.errors[:value]).to eq(["« #{subject.libelle} » doit être un nombre entier (sans chiffres après la virgule)"]) }
|
2018-10-31 19:48:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the value is not a number' do
|
|
|
|
let(:value) { 'toto' }
|
|
|
|
|
|
|
|
it { is_expected.to_not be_valid }
|
2019-07-10 13:27:36 +02:00
|
|
|
it { expect(subject.errors[:value]).to eq(["« #{subject.libelle} » doit être un nombre entier (sans chiffres après la virgule)"]) }
|
2018-10-31 19:48:28 +01:00
|
|
|
end
|
2018-11-29 14:35:42 +01:00
|
|
|
|
|
|
|
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
|
2018-10-31 19:48:28 +01:00
|
|
|
end
|
|
|
|
end
|