DEV: Style and performance improvements

Follow-up from 9db8291
This commit is contained in:
David Taylor 2018-12-11 09:58:20 +00:00
parent 671469bcc7
commit 3fedb2ad20
3 changed files with 7 additions and 8 deletions

View File

@ -4,7 +4,7 @@ class UserAssociatedAccount < ActiveRecord::Base
def self.cleanup!
# This happens when a user starts the registration flow, but doesn't complete it
# Keeping the rows doesn't cause any technical issue, but we shouldn't store PII unless it's attached to a user
self.where("user_id IS NULL AND updated_at < ?", 1.day.ago).destroy_all
self.where("user_id IS NULL AND updated_at < ?", 1.day.ago).delete_all
end
end

View File

@ -117,13 +117,12 @@ describe Auth::ManagedAuthenticator do
context 'when no matching user' do
it 'returns the correct information' do
result = nil
expect {
result = authenticator.after_authenticate(hash)
}.to change { UserAssociatedAccount.count }.by(1)
expect(result.user).to eq(nil)
expect(result.username).to eq("IAmGroot")
expect(result.email).to eq("awesome@example.com")
}.to change { UserAssociatedAccount.count }.by(1)
expect(UserAssociatedAccount.last.user).to eq(nil)
expect(UserAssociatedAccount.last.info["nickname"]).to eq("IAmGroot")
end

View File

@ -6,9 +6,9 @@ describe Jobs::CleanUpAssociatedAccounts do
it "deletes the correct records" do
freeze_time
last_week = UserAssociatedAccount.create(provider_name: "twitter", provider_uid: "1", updated_at: 7.days.ago)
today = UserAssociatedAccount.create(provider_name: "twitter", provider_uid: "12", updated_at: 12.hours.ago)
connected = UserAssociatedAccount.create(provider_name: "twitter", provider_uid: "123", user: Fabricate(:user), updated_at: 12.hours.ago)
last_week = UserAssociatedAccount.create!(provider_name: "twitter", provider_uid: "1", updated_at: 7.days.ago)
today = UserAssociatedAccount.create!(provider_name: "twitter", provider_uid: "12", updated_at: 12.hours.ago)
connected = UserAssociatedAccount.create!(provider_name: "twitter", provider_uid: "123", user: Fabricate(:user), updated_at: 12.hours.ago)
expect { subject }.to change { UserAssociatedAccount.count }.by(-1)
expect(UserAssociatedAccount.all).to contain_exactly(today, connected)