DEV: Fix flaky time sensitive uploads.rake specs (#9283)

DEV: Fix flaky time sensitive uploads.rake specs (#9283)

Also fix issues in spec where certain uploads were not considered secure

diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake
index 33c69b7..6b7473e 100644
--- a/lib/tasks/uploads.rake
+++ b/lib/tasks/uploads.rake
@@ -768,7 +768,7 @@ def adjust_acls(uploads_to_adjust_acl_for)
     Discourse.store.update_upload_ACL(upload)
     i += 1
   end
-  RakeHelpers.print_status_with_label("Updaing ACLs complete!        ", i, total_count)
+  RakeHelpers.print_status_with_label("Updating ACLs complete!        ", i, total_count)
 end
 
 def mark_all_as_secure_login_required(uploads_to_update)
diff --git a/spec/support/time_matcher.rb b/spec/support/time_matcher.rb
index ec7930e..b578fe3 100644
--- a/spec/support/time_matcher.rb
+++ b/spec/support/time_matcher.rb
@@ -16,4 +16,7 @@ RSpec::Matchers.define :eq_time do |expected_time|
   failure_message do |actual_time|
     "#{actual_time} is not within 1 millisecond of #{expected_time}"
   end
+  failure_message_when_negated do |actual_time|
+    "#{actual_time} is within 1 millisecond of #{expected_time}"
+  end
 end
diff --git a/spec/tasks/uploads_spec.rb b/spec/tasks/uploads_spec.rb
index 4041d8a..cbbd5b1 100644
--- a/spec/tasks/uploads_spec.rb
+++ b/spec/tasks/uploads_spec.rb
@@ -81,16 +81,19 @@ RSpec.describe "tasks/uploads" do
           expect(upload1.reload.secure).to eq(false)
         end
 
-        it "rebakes the posts attached" do
-          post1_baked = post1.baked_at
-          post2_baked = post2.baked_at
-          post3_baked = post3.baked_at
+        it "rebakes the posts attached for uploads that change secure status" do
+          post3.topic.update(category: Fabricate(:private_category, group: Fabricate(:group)))
+          freeze_time
+
+          post1.update_columns(baked_at: 1.week.ago)
+          post2.update_columns(baked_at: 1.week.ago)
+          post3.update_columns(baked_at: 1.week.ago)
 
           invoke_task
 
-          expect(post1.reload.baked_at).not_to eq(post1_baked)
-          expect(post2.reload.baked_at).not_to eq(post2_baked)
-          expect(post3.reload.baked_at).not_to eq(post3_baked)
+          expect(post1.reload.baked_at).to eq_time(1.week.ago)
+          expect(post2.reload.baked_at).to eq_time(1.week.ago)
+          expect(post3.reload.baked_at).not_to eq_time(1.week.ago)
         end
 
         context "for an upload that is already secure and does not need to change" do
@@ -98,12 +101,17 @@ RSpec.describe "tasks/uploads" do
             post3.topic.update(archetype: 'private_message', category: nil)
             upload2.update(access_control_post: post3)
             upload2.update_secure_status
+            upload3.update(access_control_post: post3)
+            upload3.update_secure_status
           end
 
           it "does not rebake the associated post" do
-            post3_baked = post3.baked_at.to_s
+            freeze_time
+
+            post3.update_columns(baked_at: 1.week.ago)
             invoke_task
-            expect(post3.reload.baked_at.to_s).to eq(post3_baked)
+
+            expect(post3.reload.baked_at).to eq_time(1.week.ago)
           end
 
           it "does not attempt to update the acl" do
@@ -168,11 +176,14 @@ RSpec.describe "tasks/uploads" do
     end
 
     it "rebakes the associated posts" do
-      baked_post1 = post1.baked_at
-      baked_post2 = post2.baked_at
+      freeze_time
+
+      post1.update_columns(baked_at: 1.week.ago)
+      post2.update_columns(baked_at: 1.week.ago)
       invoke_task
-      expect(post1.reload.baked_at).not_to eq(baked_post1)
-      expect(post2.reload.baked_at).not_to eq(baked_post2)
+
+      expect(post1.reload.baked_at).not_to eq_time(1.week.ago)
+      expect(post2.reload.baked_at).not_to eq_time(1.week.ago)
     end
 
     it "updates the affected ACLs" do

GitHub sha: efd5fb66

This commit appears in #9283 which was merged by martin.