From 3a5eeaf9e672f6a4d0c116069cfbef2ace68e560 Mon Sep 17 00:00:00 2001
From: tmn21 <tmn21@inf.ufpr.br>
Date: Wed, 26 Jul 2023 11:58:11 -0300
Subject: [PATCH] ISSUE #52: UPDATE high_streak function

---
 app/models/user.rb | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/app/models/user.rb b/app/models/user.rb
index 3ddf3ba4..f0165024 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -388,6 +388,12 @@ class User < ApplicationRecord
     end
   end
 
+  def update_high_streak()
+    if self.high_streak < self.streak
+      self.update(high_streak: streak)
+    end
+  end
+
   def update_streak()
     if self.last_action_at==Date.today
       return
@@ -397,9 +403,7 @@ class User < ApplicationRecord
     if self.last_action_at==Date.yesterday    
       self.update(last_action_at: Date.today)
       self.update(streak: streak+1)
-      if self.high_streak < self.streak
-        self.update(high_streak: streak)
-      end
+      update_high_streak
       return
     end
     
@@ -407,6 +411,7 @@ class User < ApplicationRecord
     if (Date.today - self.last_action_at).to_i >= 2
       self.update(last_action_at: Date.today)
       self.update(streak: 1)
+      update_high_streak
     end
 
   end
-- 
GitLab