From 80449d39d345896b57d93af037a1056a71fdccbe Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Wed, 28 Aug 2024 17:03:43 +1000 Subject: [PATCH] FIX: Flaky flags spec (#28591) Because of caching, whenever flags are created, they have to be destroyed to not modify the state. --- spec/lib/guardian/flag_guardian_spec.rb | 4 +++- spec/serializers/flag_serializer_spec.rb | 10 +++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/spec/lib/guardian/flag_guardian_spec.rb b/spec/lib/guardian/flag_guardian_spec.rb index 77680d4fcdc..5fbf0eb14ea 100644 --- a/spec/lib/guardian/flag_guardian_spec.rb +++ b/spec/lib/guardian/flag_guardian_spec.rb @@ -13,10 +13,12 @@ RSpec.describe FlagGuardian do expect(Guardian.new(admin).can_create_flag?).to eq(true) expect(Guardian.new(user).can_create_flag?).to eq(false) - Fabricate(:flag) + flag = Fabricate(:flag) expect(Guardian.new(admin).can_create_flag?).to eq(false) expect(Guardian.new(user).can_create_flag?).to eq(false) + + flag.destroy! end end diff --git a/spec/serializers/flag_serializer_spec.rb b/spec/serializers/flag_serializer_spec.rb index 507e3e8c078..6f8f913642e 100644 --- a/spec/serializers/flag_serializer_spec.rb +++ b/spec/serializers/flag_serializer_spec.rb @@ -16,16 +16,12 @@ RSpec.describe FlagSerializer do end context "when custom flag" do - fab!(:flag) { Fabricate(:flag, name: "custom title", description: "custom description") } - - it "returns translated name" do + it "returns translated name and description" do + flag = Fabricate(:flag, name: "custom title", description: "custom description") serialized = described_class.new(flag, used_flag_ids: []).as_json expect(serialized[:flag][:name]).to eq("custom title") - end - - it "returns translated description" do - serialized = described_class.new(flag, used_flag_ids: []).as_json expect(serialized[:flag][:description]).to eq("custom description") + flag.destroy! end end