france_connect: raise an error if some validation error occurs

If a validation error occurs in `find_or_create`, an object without `id`
will be returned–and the code will crash soon after.

Ensure that we crash immediately, so that we can report the root cause
(the validation error) instead of a seemingly-unrelated crash later.
This commit is contained in:
Pierre de La Morinerie 2019-07-08 17:30:07 +02:00
parent 6b27ac8514
commit 06afc3890f

View file

@ -13,7 +13,7 @@ class FranceConnect::ParticulierController < ApplicationController
fetched_fci.tap(&:save)
if fci.user.nil?
user = User.find_or_create_by(email: fci.email_france_connect.downcase) do |new_user|
user = User.find_or_create_by!(email: fci.email_france_connect.downcase) do |new_user|
new_user.password = Devise.friendly_token[0, 20]
new_user.confirmed_at = Time.zone.now
end