From 64605519da459191d1d764009b7a19fdb1e149f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guitaut?= Date: Fri, 18 Oct 2024 17:19:43 +0200 Subject: [PATCH] DEV: Fix flaky specs related to flag services Creating or updating flags generates global side effects. Sometimes it seems the state can leak from the flag specs. This is probably related to the use of `fab!`. This patch replaces those calls with standard `let`s. While the overall performances of these tests will be a little less good, their state should not leak anymore. --- spec/services/flags/destroy_flag_spec.rb | 2 +- spec/services/flags/toggle_flag_spec.rb | 2 +- spec/services/flags/update_flag_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/services/flags/destroy_flag_spec.rb b/spec/services/flags/destroy_flag_spec.rb index 1d48cd4562a..8569cdb3055 100644 --- a/spec/services/flags/destroy_flag_spec.rb +++ b/spec/services/flags/destroy_flag_spec.rb @@ -3,9 +3,9 @@ RSpec.describe(Flags::DestroyFlag) do subject(:result) { described_class.call(**params, **dependencies) } - fab!(:flag) fab!(:current_user) { Fabricate(:admin) } + let(:flag) { Fabricate(:flag) } let(:params) { { id: flag_id } } let(:dependencies) { { guardian: current_user.guardian } } let(:flag_id) { flag.id } diff --git a/spec/services/flags/toggle_flag_spec.rb b/spec/services/flags/toggle_flag_spec.rb index 2b6f5527754..3ba43240ba3 100644 --- a/spec/services/flags/toggle_flag_spec.rb +++ b/spec/services/flags/toggle_flag_spec.rb @@ -8,9 +8,9 @@ RSpec.describe(Flags::ToggleFlag) do describe ".call" do subject(:result) { described_class.call(**params, **dependencies) } - fab!(:flag) fab!(:current_user) { Fabricate(:admin) } + let(:flag) { Fabricate(:flag) } let(:flag_id) { flag.id } let(:params) { { flag_id: flag_id } } let(:dependencies) { { guardian: current_user.guardian } } diff --git a/spec/services/flags/update_flag_spec.rb b/spec/services/flags/update_flag_spec.rb index 3060debd7cf..17fcde871a0 100644 --- a/spec/services/flags/update_flag_spec.rb +++ b/spec/services/flags/update_flag_spec.rb @@ -13,9 +13,9 @@ RSpec.describe(Flags::UpdateFlag) do describe ".call" do subject(:result) { described_class.call(**params, **dependencies) } - fab!(:flag) fab!(:current_user) { Fabricate(:admin) } + let(:flag) { Fabricate(:flag) } let(:params) { { id: flag_id, name:, description:, applies_to:, require_message:, enabled: } } let(:dependencies) { { guardian: current_user.guardian } } let(:flag_id) { flag.id }