FIX: ManagedAuthenticator should automatically update last_used time

FIX: ManagedAuthenticator should automatically update last_used time

diff --git a/lib/auth/managed_authenticator.rb b/lib/auth/managed_authenticator.rb
index b7218b9..a56989c 100644
--- a/lib/auth/managed_authenticator.rb
+++ b/lib/auth/managed_authenticator.rb
@@ -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!
 
diff --git a/spec/components/auth/managed_authenticator_spec.rb b/spec/components/auth/managed_authenticator_spec.rb
index 63950ce..f088f4f 100644
--- a/spec/components/auth/managed_authenticator_spec.rb
+++ b/spec/components/auth/managed_authenticator_spec.rb
@@ -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")

GitHub sha: b907924c

2 Likes