2017-03-29 13:37:07 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ChampsService do
|
2018-02-13 17:00:19 +01:00
|
|
|
let(:type_de_champ) { create(:type_de_champ) }
|
|
|
|
let(:type_de_champ_mandatory) { create(:type_de_champ, libelle: 'mandatory', mandatory: true) }
|
|
|
|
let(:type_de_champ_datetime) { create(:type_de_champ, type_champ: :datetime) }
|
2018-02-09 17:50:10 +01:00
|
|
|
let!(:champ) { type_de_champ.champ.create(value: 'toto') }
|
|
|
|
let!(:champ_mandatory_empty) { type_de_champ_mandatory.champ.create }
|
|
|
|
let!(:champ_datetime) { type_de_champ_datetime.champ.create }
|
2017-03-30 16:12:01 +02:00
|
|
|
let!(:champs) { [champ, champ_mandatory_empty, champ_datetime] }
|
2017-03-29 13:37:07 +02:00
|
|
|
|
2017-03-30 16:12:01 +02:00
|
|
|
describe 'save_champs' do
|
2017-03-29 13:37:07 +02:00
|
|
|
before :each do
|
|
|
|
params_hash = {
|
|
|
|
champs: {
|
|
|
|
"'#{champ.id}'" => 'yop',
|
|
|
|
"'#{champ_datetime.id}'" => 'd'
|
|
|
|
},
|
|
|
|
time_hour: { "'#{champ_datetime.id}'" => '12' },
|
|
|
|
time_minute: { "'#{champ_datetime.id}'" => '24' }
|
|
|
|
}
|
2017-03-30 16:12:01 +02:00
|
|
|
ChampsService.save_champs(champs, params_hash)
|
2017-03-29 13:37:07 +02:00
|
|
|
champs.each(&:reload)
|
|
|
|
end
|
|
|
|
|
2017-03-30 16:12:01 +02:00
|
|
|
it 'saves the changed champ' do
|
|
|
|
expect(champ.value).to eq('yop')
|
2017-03-29 13:37:07 +02:00
|
|
|
end
|
|
|
|
|
2017-03-30 16:12:01 +02:00
|
|
|
it 'parses and save the date' do
|
2018-01-19 17:42:55 +01:00
|
|
|
expect(champ_datetime.value).to eq(nil)
|
2017-03-30 16:12:01 +02:00
|
|
|
end
|
|
|
|
end
|
2017-03-29 13:37:07 +02:00
|
|
|
|
2017-03-30 16:12:01 +02:00
|
|
|
describe 'build_error_message' do
|
|
|
|
it 'adds error for the missing mandatory champ' do
|
|
|
|
expect(ChampsService.build_error_messages(champs)).to match(['Le champ mandatory doit être rempli.'])
|
2017-03-29 13:37:07 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|