demarches-normaliennes/spec/services/champs_service_spec.rb

41 lines
1.2 KiB
Ruby
Raw Normal View History

2017-03-29 13:37:07 +02:00
require 'spec_helper'
describe ChampsService do
let!(:champ) { Champ.create(value: 'toto', type_de_champ: TypeDeChamp.new) }
let!(:champ_mandatory_empty) { Champ.create(type_de_champ: TypeDeChamp.new(libelle: 'mandatory', mandatory: true)) }
let!(:champ_datetime) do
champ_datetime = TypeDeChamp.new(type_champ: 'datetime')
Champ.create(type_de_champ: champ_datetime)
end
let!(:champs) { [champ, champ_mandatory_empty, champ_datetime] }
2017-03-29 13:37:07 +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' }
}
ChampsService.save_champs(champs, params_hash)
2017-03-29 13:37:07 +02:00
champs.each(&:reload)
end
it 'saves the changed champ' do
expect(champ.value).to eq('yop')
2017-03-29 13:37:07 +02:00
end
it 'parses and save the date' do
expect(champ_datetime.value).to eq('d 12:24')
end
end
2017-03-29 13:37:07 +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