FIX: extract reset_last_seen_cache! in user_spec (#9808)

FIX: extract reset_last_seen_cache! in user_spec (#9808)

Helper method to avoid code duplication

diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 637e2fd..89d5f62 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -874,7 +874,7 @@ describe User do
     end
 
     after do
-      Discourse.redis.del("user:#{user.id}:#{Time.zone.now.to_date}")
+      reset_last_seen_cache!(user)
     end
 
     it "should act correctly" do
@@ -908,7 +908,7 @@ describe User do
     let!(:second_visit_date) { 2.hours.from_now }
 
     after do
-      Discourse.redis.del("user:#{user.id}:#{Time.zone.now.to_date}")
+      reset_last_seen_cache!(user)
     end
 
     it "should update the last seen value" do
@@ -984,9 +984,9 @@ describe User do
 
     describe 'with no previous values' do
       after do
-        Discourse.redis.del("user:#{user.id}:#{Time.zone.now.to_date}")
+        reset_last_seen_cache!(user)
         unfreeze_time
-        Discourse.redis.del("user:#{user.id}:#{Time.zone.now.to_date}")
+        reset_last_seen_cache!(user)
       end
 
       it "updates last_seen_at" do
@@ -1316,7 +1316,7 @@ describe User do
       let!(:now) { Time.zone.now }
       before { user.update_last_seen!(now) }
       after do
-        Discourse.redis.del("user:#{user.id}:#{now.to_date}")
+        reset_last_seen_cache!(user)
       end
 
       it "with existing UserVisit record, increments the posts_read value" do
@@ -2374,4 +2374,8 @@ describe User do
       expect(user2.recent_time_read).to eq(50)
     end
   end
+
+  def reset_last_seen_cache!(user)
+    Discourse.redis.del("user:#{user.id}:#{Time.zone.now.to_date}")
+  end
 end

GitHub sha: ea63fa7d

This commit appears in #9808 which was merged by lis2.