DEV: improve flaky spec

DEV: improve flaky spec

This handles a lot of date calculations, keep the baseline time consistent so it is not prone to issues when running out UTC threshold

diff --git a/spec/models/directory_item_spec.rb b/spec/models/directory_item_spec.rb
index 54f8d72..fd8971f 100644
--- a/spec/models/directory_item_spec.rb
+++ b/spec/models/directory_item_spec.rb
@@ -51,6 +51,7 @@ describe DirectoryItem do
 
   context 'refresh' do
     before do
+      freeze_time DateTime.parse('2017-02-02 12:00')
       UserActionManager.enable
     end
 
@@ -89,11 +90,13 @@ describe DirectoryItem do
     it "handles users with no activity" do
       post = nil
 
-      freeze_time(2.years.ago) do
-        post = create_post
-        # Create records for that activity
-        DirectoryItem.refresh!
-      end
+      freeze_time(2.years.ago)
+
+      post = create_post
+      # Create records for that activity
+      DirectoryItem.refresh!
+
+      freeze_time(2.years.from_now)
 
       DirectoryItem.refresh!
       [:yearly, :monthly, :weekly, :daily, :quarterly].each do |period|

GitHub sha: 926bd712

1 Like