FIX: Heisentest

FIX: Heisentest

We use the id of the upload to calculate a depth partition in the filename. This test would fail if your database had a higher seed because the depth it was looking for was hard coded to 1.

The solution was to not save the records (which is faster anyway) and specify the id of the upload to make the hash deterministic.

diff --git a/spec/components/file_store/base_store_spec.rb b/spec/components/file_store/base_store_spec.rb
index 3de0ff2..623b164 100644
--- a/spec/components/file_store/base_store_spec.rb
+++ b/spec/components/file_store/base_store_spec.rb
@@ -21,16 +21,16 @@ RSpec.describe FileStore::BaseStore do
   end
 
   describe '#get_path_for_optimized_image' do
-    let(:upload) { Fabricate(:upload) }
+    let(:upload) { Fabricate.build(:upload, id: 100) }
     let(:optimized_path) { "optimized/1X/#{upload.sha1}_1_100x200.png" }
 
     it 'should return the right path' do
-      optimized = Fabricate(:optimized_image, upload: upload, version: 1)
+      optimized = Fabricate.build(:optimized_image, upload: upload, version: 1)
       expect(FileStore::BaseStore.new.get_path_for_optimized_image(optimized)).to eq(optimized_path)
     end
 
     it 'should return the right path for `nil` version' do
-      optimized = Fabricate(:optimized_image, upload: upload, version: nil)
+      optimized = Fabricate.build(:optimized_image, upload: upload, version: nil)
       expect(FileStore::BaseStore.new.get_path_for_optimized_image(optimized)).to eq(optimized_path)
     end
   end

GitHub sha: bee68bba

1 Like

FIX: Heisentest