DEV: Fix extremely rare test failure

DEV: Fix extremely rare test failure

If this was the first test to run, the Fabricate(:user) would be given
the same ID as the Fabricate.build(:user, id: 1). This works around it.

From e8f32dd3bad67822824541f1677987bf9f8f7858 Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Thu, 6 Dec 2018 13:32:56 +0000
Subject: [PATCH] DEV: Fix extremely rare test failure

If this was the first test to run, the Fabricate(:user) would be given
the same ID as the Fabricate.build(:user, id: 1). This works around it.

diff --git a/spec/components/guardian/user_guardian_spec.rb b/spec/components/guardian/user_guardian_spec.rb
index 248a81f..e37245c 100644
--- a/spec/components/guardian/user_guardian_spec.rb
+++ b/spec/components/guardian/user_guardian_spec.rb
@@ -108,6 +108,9 @@ describe UserGuardian do
     end
 
     context "hidden profile" do
+      # Mixing Fabricate.build() and Fabricate() could cause ID clashes, so override :user
+      let(:user) { Fabricate(:user) }
+
       let(:hidden_user) do
         result = Fabricate(:user)
         result.user_option.update_column(:hide_profile_and_presence, true)

GitHub

2 Likes