demarches-normaliennes/app/models/individual.rb
Pierre de La Morinerie 88373ddf20 individual: raise when the individual object cannot be created
Currently, a number of dossiers in production are for procedures for
individuals, but don't have a `individual` object.

This is probably because creating the Individual from France Connect
infos fails – but fails quietly, and nullify the relationship.

As a first step, we now raise an exception when the creation from FC
infos fails. We will then identify the issue, and see if we can fix it –
or if we should be resilient to this kind of issues.
2019-11-12 18:29:37 +01:00

19 lines
628 B
Ruby

class Individual < ApplicationRecord
belongs_to :dossier
validates :dossier_id, uniqueness: true
validates :gender, presence: true, allow_nil: false, on: :update
validates :nom, presence: true, allow_blank: false, allow_nil: false, on: :update
validates :prenom, presence: true, allow_blank: false, allow_nil: false, on: :update
GENDER_MALE = 'M.'
GENDER_FEMALE = 'Mme'
def self.create_from_france_connect(fc_information)
create!(
nom: fc_information.family_name,
prenom: fc_information.given_name,
gender: fc_information.gender == 'female' ? GENDER_FEMALE : GENDER_MALE
)
end
end