associate_user take a target email

This commit is contained in:
simon lehericey 2021-10-13 00:18:00 +02:00
parent 09f828a6a2
commit f6879eba60
3 changed files with 8 additions and 5 deletions

View file

@ -13,7 +13,7 @@ class FranceConnect::ParticulierController < ApplicationController
fci = FranceConnectService.find_or_retrieve_france_connect_information(params[:code]) fci = FranceConnectService.find_or_retrieve_france_connect_information(params[:code])
if fci.user.nil? if fci.user.nil?
fci.associate_user! fci.associate_user!(fci.email_france_connect)
end end
user = fci.user user = fci.user

View file

@ -24,10 +24,10 @@ class FranceConnectInformation < ApplicationRecord
validates :france_connect_particulier_id, presence: true, allow_blank: false, allow_nil: false validates :france_connect_particulier_id, presence: true, allow_blank: false, allow_nil: false
def associate_user! def associate_user!(email)
begin begin
user = User.create!( user = User.create!(
email: email_france_connect.downcase, email: email.downcase,
password: Devise.friendly_token[0, 20], password: Devise.friendly_token[0, 20],
confirmed_at: Time.zone.now confirmed_at: Time.zone.now
) )

View file

@ -9,13 +9,16 @@ describe FranceConnectInformation, type: :model do
describe 'associate_user!' do describe 'associate_user!' do
context 'when there is no user with same email' do context 'when there is no user with same email' do
let(:email) { 'A@email.com' }
let(:fci) { build(:france_connect_information) } let(:fci) { build(:france_connect_information) }
let(:subject) { fci.associate_user! }
subject { fci.associate_user!(email) }
it { expect { subject }.to change(User, :count).by(1) } it { expect { subject }.to change(User, :count).by(1) }
it do it do
subject subject
expect(fci.user.email).to eq(fci.email_france_connect) expect(fci.user.email).to eq('a@email.com')
end end
end end
end end