DEV: correct heisentest testing for avatars

DEV: correct heisentest testing for avatars

If for some reason we created an upload with id 1 in the test then the test would fail. This can happen if this is the absolute first test to run on the db.

Fix sets the upload to a legitimate one which in turn means the last upload will not be upload id 1 and stops using id hard coding for the testing.

diff --git a/spec/models/user_avatar_spec.rb b/spec/models/user_avatar_spec.rb
index 7571377..fd28ca4 100644
--- a/spec/models/user_avatar_spec.rb
+++ b/spec/models/user_avatar_spec.rb
@@ -125,8 +125,10 @@ describe UserAvatar do
     end
 
     it 'can leave gravatar alone' do
-      user = Fabricate(:user, uploaded_avatar_id: 1)
-      user.user_avatar.update_columns(gravatar_upload_id: 1)
+      upload = Fabricate(:upload)
+
+      user = Fabricate(:user, uploaded_avatar_id: upload.id)
+      user.user_avatar.update_columns(gravatar_upload_id: upload.id)
 
       stub_request(:get, "http://thisfakesomething.something.com/")
         .to_return(status: 200, body: file_from_fixtures("logo.png"), headers: {})
@@ -138,8 +140,12 @@ describe UserAvatar do
       end.to change { Upload.count }.by(1)
 
       user.reload
-      expect(user.uploaded_avatar_id).to eq(1)
-      expect(user.user_avatar.custom_upload_id).to eq(Upload.last.id)
+      expect(user.uploaded_avatar_id).to eq(upload.id)
+
+      last_id = Upload.last.id
+
+      expect(last_id).not_to eq(upload.id)
+      expect(user.user_avatar.custom_upload_id).to eq(last_id)
     end
 
     describe 'when avatar url returns an invalid status code' do

GitHub sha: a84aaf19

1 Like