Merge pull request #11126 from colinux/fix-useless-exception
ETQ usager, pas d'erreur inutile lors d'un double callback FranceConnect
This commit is contained in:
commit
4eb9322a4f
2 changed files with 6 additions and 11 deletions
|
@ -15,6 +15,8 @@ class FranceConnectInformation < ApplicationRecord
|
||||||
password: Devise.friendly_token[0, 20],
|
password: Devise.friendly_token[0, 20],
|
||||||
confirmed_at: Time.zone.now
|
confirmed_at: Time.zone.now
|
||||||
)
|
)
|
||||||
|
|
||||||
|
update_attribute('user_id', user.id)
|
||||||
rescue ActiveRecord::RecordNotUnique
|
rescue ActiveRecord::RecordNotUnique
|
||||||
# ignore this exception because we check before if user is nil.
|
# ignore this exception because we check before if user is nil.
|
||||||
# exception can be raised in race conditions, when FranceConnect calls callback 2 times.
|
# exception can be raised in race conditions, when FranceConnect calls callback 2 times.
|
||||||
|
@ -23,7 +25,6 @@ class FranceConnectInformation < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
clean_tokens_and_requested_email
|
clean_tokens_and_requested_email
|
||||||
update_attribute('user_id', user.id)
|
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -50,25 +50,19 @@ describe FranceConnectInformation, type: :model do
|
||||||
allow(fci).to receive(:send_custom_confirmation_instructions)
|
allow(fci).to receive(:send_custom_confirmation_instructions)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises an error' do
|
it 'is noop' do
|
||||||
expect { fci.safely_associate_user!(email) }.to raise_error(NoMethodError)
|
expect(fci.safely_associate_user!(email)).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create a new user' do
|
it 'does not create a new user' do
|
||||||
expect {
|
expect {
|
||||||
begin
|
fci.safely_associate_user!(email)
|
||||||
fci.safely_associate_user!(email)
|
|
||||||
rescue NoMethodError
|
|
||||||
end
|
|
||||||
}.to_not change(User, :count)
|
}.to_not change(User, :count)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not associate with any user' do
|
it 'does not associate with any user' do
|
||||||
expect(fci.user).to be_nil
|
expect(fci.user).to be_nil
|
||||||
begin
|
fci.safely_associate_user!(email)
|
||||||
fci.safely_associate_user!(email)
|
|
||||||
rescue NoMethodError
|
|
||||||
end
|
|
||||||
expect(fci.reload.user).to be_nil
|
expect(fci.reload.user).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue