2018-10-31 19:48:03 +01:00
describe Champs :: DecimalNumberChamp do
2024-03-29 12:25:24 +01:00
let ( :champ ) { build ( :champ_decimal_number , value : ) }
subject { champ . validate ( :champs_public_value ) }
2018-10-31 19:48:03 +01:00
2024-03-29 12:25:24 +01:00
describe 'validation' do
2018-10-31 19:48:03 +01:00
context 'when the value is integer number' do
let ( :value ) { 2 }
2024-03-29 12:25:24 +01:00
it { is_expected . to be_truthy }
2018-10-31 19:48:03 +01:00
end
context 'when the value is decimal number' do
let ( :value ) { 2 . 6 }
2024-03-29 12:25:24 +01:00
it { is_expected . to be_truthy }
2018-10-31 19:48:03 +01:00
end
context 'when the value is not a number' do
let ( :value ) { 'toto' }
2024-03-29 12:25:24 +01:00
it 'is not valid and contains expected error' do
expect ( subject ) . to be_falsey
expect ( champ . errors [ :value ] ) . to eq ( [ " « #{ champ . libelle } » doit comprendre maximum 3 chiffres après la virgule " , " « #{ champ . libelle } » n'est pas un nombre " ] )
end
2024-03-18 18:10:26 +01:00
end
context 'when the value has too many decimal' do
let ( :value ) { '2.6666' }
2024-03-29 12:25:24 +01:00
it 'is not valid and contains expected error' do
expect ( subject ) . to be_falsey
expect ( champ . errors [ :value ] ) . to eq ( [ " « #{ champ . libelle } » doit comprendre maximum 3 chiffres après la virgule " ] )
end
2018-10-31 19:48:03 +01:00
end
2018-11-29 14:35:42 +01:00
context 'when the value is blank' do
let ( :value ) { '' }
2024-03-29 12:25:24 +01:00
it { is_expected . to be_truthy }
2018-11-29 14:35:42 +01:00
end
context 'when the value is nil' do
let ( :value ) { nil }
2024-03-29 12:25:24 +01:00
it { is_expected . to be_truthy }
end
context 'when the champ is private, value is invalid, but validation is public' do
let ( :champ ) { build ( :champ_decimal_number , :private , value : ) }
let ( :value ) { '2.6666' }
it { is_expected . to be_truthy }
2018-11-29 14:35:42 +01:00
end
2018-10-31 19:48:03 +01:00
end
end