FIX: Heisentest - Stored uploads don't always start with 1X

FIX: Heisentest - Stored uploads don’t always start with 1X

This is a common pattern we see in tests. The id of the upload is used to create the URL and we assume the id will always be in a certain range which depends on the database.

diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb
index 5f7801d..cb17f33 100644
--- a/spec/components/cooked_post_processor_spec.rb
+++ b/spec/components/cooked_post_processor_spec.rb
@@ -1019,7 +1019,8 @@ describe CookedPostProcessor do
           extension: "png",
-        upload.update_column(:url, "#{SiteSetting.Upload.absolute_base_url}/#{}")
+        stored_path =
+        upload.update_column(:url, "#{SiteSetting.Upload.absolute_base_url}/#{stored_path}")
         the_post = Fabricate(:post, raw: %Q{This post has a local emoji :+1: and an external upload\n\n![smallest.png|10x20](#{upload.short_url})})
@@ -1028,7 +1029,7 @@ describe CookedPostProcessor do
         expect(cpp.html).to match_html <<~HTML
           <p>This post has a local emoji <img src="" title=":+1:" class="emoji" alt=":+1:"> and an external upload</p>
-          <p><img src="{upload_sha1}.png" alt="smallest.png" width="10" height="20"></p>
+          <p><img src="{stored_path}" alt="smallest.png" width="10" height="20"></p>

GitHub sha: 45db98dd


This never happens to me as I reset my test database every time I run the specs…

@ZogStriP you never use autospec?

When I develop I do. But every morning and most of the time before I push some code I reset the db and run rspec.

I guess I don’t leave the test db long enough to generate 1000 upload records.

Still, I don’t think tests should be based on certain id values. Or, if they are, those ids should be seeded as such.


I agree 100% with you. I just explained why I never hit that case and thus never got to fix that test.