create_merge_token!
This commit is contained in:
parent
34862f41e0
commit
09f828a6a2
2 changed files with 18 additions and 0 deletions
|
@ -42,6 +42,13 @@ class FranceConnectInformation < ApplicationRecord
|
|||
touch # needed to update updated_at column
|
||||
end
|
||||
|
||||
def create_merge_token!
|
||||
merge_token = SecureRandom.uuid
|
||||
update(merge_token: merge_token, merge_token_created_at: Time.zone.now)
|
||||
|
||||
merge_token
|
||||
end
|
||||
|
||||
def valid_for_merge?
|
||||
(MERGE_VALIDITY.ago < merge_token_created_at) && user_id.nil?
|
||||
end
|
||||
|
|
|
@ -43,4 +43,15 @@ describe FranceConnectInformation, type: :model do
|
|||
it { is_expected.to be(false) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#create_merge_token!' do
|
||||
let(:fci) { create(:france_connect_information) }
|
||||
|
||||
it 'returns a merge_token and register it s creation date' do
|
||||
token = fci.create_merge_token!
|
||||
|
||||
expect(fci.merge_token).to eq(token)
|
||||
expect(fci.merge_token_created_at).not_to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue