DEV: Style and performance improvements

DEV: Style and performance improvements

Follow-up from 9db8291

From 3fedb2ad2019ceb12b974f8d54d1d7dd17c8223e Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Tue, 11 Dec 2018 09:58:20 +0000
Subject: [PATCH] DEV: Style and performance improvements

Follow-up from 9db8291

diff --git a/app/models/user_associated_account.rb b/app/models/user_associated_account.rb
index ef85326..d210781 100644
--- a/app/models/user_associated_account.rb
+++ b/app/models/user_associated_account.rb
@@ -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
 
diff --git a/spec/components/auth/managed_authenticator_spec.rb b/spec/components/auth/managed_authenticator_spec.rb
index 870536b..63950ce 100644
--- a/spec/components/auth/managed_authenticator_spec.rb
+++ b/spec/components/auth/managed_authenticator_spec.rb
@@ -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)
+          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(result.user).to eq(nil)
-        expect(result.username).to eq("IAmGroot")
-        expect(result.email).to eq("awesome@example.com")
         expect(UserAssociatedAccount.last.user).to eq(nil)
         expect(UserAssociatedAccount.last.info["nickname"]).to eq("IAmGroot")
       end
diff --git a/spec/jobs/clean_up_associated_accounts_spec.rb b/spec/jobs/clean_up_associated_accounts_spec.rb
index 4874ad5..38502b8 100644
--- a/spec/jobs/clean_up_associated_accounts_spec.rb
+++ b/spec/jobs/clean_up_associated_accounts_spec.rb
@@ -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)

GitHub

1 Like