2016-08-30 11:18:43 +02:00
|
|
|
describe Individual do
|
2016-12-20 17:01:16 +01:00
|
|
|
it { is_expected.to have_db_column(:gender) }
|
2016-08-30 11:18:43 +02:00
|
|
|
it { is_expected.to have_db_column(:nom) }
|
|
|
|
it { is_expected.to have_db_column(:prenom) }
|
2020-07-20 16:53:25 +02:00
|
|
|
it { is_expected.to belong_to(:dossier).required }
|
2018-02-26 12:01:28 +01:00
|
|
|
|
2018-03-20 16:00:30 +01:00
|
|
|
describe "#save" do
|
2018-02-26 12:01:28 +01:00
|
|
|
let(:individual) { build(:individual) }
|
|
|
|
|
|
|
|
subject { individual.save }
|
|
|
|
|
|
|
|
context "with birthdate" do
|
|
|
|
before do
|
|
|
|
individual.birthdate = birthdate_from_user
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
context "and the format is dd/mm/yyy " do
|
|
|
|
let(:birthdate_from_user) { "12/11/1980" }
|
|
|
|
|
2018-04-03 16:38:54 +02:00
|
|
|
it { expect(individual.birthdate).to eq(Date.new(1980, 11, 12)) }
|
2018-02-26 12:01:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "and the format is ISO" do
|
|
|
|
let(:birthdate_from_user) { "1980-11-12" }
|
|
|
|
|
2018-04-03 16:38:54 +02:00
|
|
|
it { expect(individual.birthdate).to eq(Date.new(1980, 11, 12)) }
|
2018-02-26 12:01:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "and the format is WTF" do
|
|
|
|
let(:birthdate_from_user) { "1980 1 12" }
|
|
|
|
|
2018-04-03 16:38:54 +02:00
|
|
|
it { expect(individual.birthdate).to be_nil }
|
2018-02-26 12:01:28 +01:00
|
|
|
end
|
|
|
|
end
|
2023-11-27 15:52:55 +01:00
|
|
|
|
|
|
|
context 'when an individual has an invalid notification_method' do
|
|
|
|
let(:invalid_individual) { build(:individual, notification_method: 'invalid_method') }
|
|
|
|
|
|
|
|
it 'raises an ArgumentError' do
|
|
|
|
expect {
|
|
|
|
invalid_individual.valid?
|
|
|
|
}.to raise_error(ArgumentError, "'invalid_method' is not a valid notification_method")
|
|
|
|
end
|
|
|
|
end
|
2018-02-26 12:01:28 +01:00
|
|
|
end
|
2016-08-30 11:18:43 +02:00
|
|
|
end
|