FIX: ManagedAuthenticator should automatically update last_used time

This commit is contained in:
David Taylor 2019-02-27 15:29:26 +00:00
parent cafbb3aea7
commit b907924c93
2 changed files with 4 additions and 1 deletions

View File

@ -45,6 +45,8 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
association.credentials = auth_token[:credentials] || {}
association.extra = auth_token[:extra] || {}
association.last_used = Time.zone.now
# Save to the DB. Do this even if we don't have a user - it might be linked up later in after_create_account
association.save!

View File

@ -39,11 +39,12 @@ describe Auth::ManagedAuthenticator do
describe 'after_authenticate' do
it 'can match account from an existing association' do
user = Fabricate(:user)
associated = UserAssociatedAccount.create!(user: user, provider_name: 'myauth', provider_uid: "1234")
associated = UserAssociatedAccount.create!(user: user, provider_name: 'myauth', provider_uid: "1234", last_used: 1.year.ago)
result = authenticator.after_authenticate(hash)
expect(result.user.id).to eq(user.id)
associated.reload
expect(associated.last_used).to be >= 1.day.ago
expect(associated.info["name"]).to eq("Best Display Name")
expect(associated.info["email"]).to eq("awesome@example.com")
expect(associated.credentials["token"]).to eq("supersecrettoken")