FIX: flaky flags spec after refactoring (#29325)

The bug was introduced here https://github.com/discourse/discourse/pull/29258

It is very important for flags to reset to their original state because they are cached and shared between specs.
This commit is contained in:
Krzysztof Kotlarek 2024-10-22 13:18:57 +11:00 committed by GitHub
parent fa42565515
commit 44c8470813
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 0 deletions

View File

@ -41,6 +41,8 @@ RSpec.describe(Flags::CreateFlag) do
let!(:flag) { Fabricate(:flag, name:) }
it { is_expected.to fail_a_policy(:unique_name) }
after { flag.destroy! }
end
context "when everything's ok" do
@ -54,6 +56,8 @@ RSpec.describe(Flags::CreateFlag) do
)
end
after { flag.destroy! }
it { is_expected.to run_successfully }
it "creates the flag" do

View File

@ -11,24 +11,28 @@ RSpec.describe(Flags::DestroyFlag) do
let(:flag_id) { flag.id }
context "when model is not found" do
after { flag.destroy! }
let(:flag_id) { 0 }
it { is_expected.to fail_to_find_a_model(:flag) }
end
context "when the flag is a system one" do
after { flag.destroy! }
let(:flag) { Flag.first }
it { is_expected.to fail_a_policy(:not_system) }
end
context "when the flag has been used" do
after { flag.destroy! }
let!(:post_action) { Fabricate(:post_action, post_action_type_id: flag.id) }
it { is_expected.to fail_a_policy(:not_used) }
end
context "when user is not allowed to perform the action" do
after { flag.destroy! }
fab!(:current_user) { Fabricate(:user) }
it { is_expected.to fail_a_policy(:invalid_access) }

View File

@ -42,6 +42,10 @@ RSpec.describe(Flags::ReorderFlag) do
end
context "when everything's ok" do
after do
described_class.call(flag_id: flag.id, guardian: current_user.guardian, direction: "down")
end
it { is_expected.to run_successfully }
it "moves the flag" do

View File

@ -34,6 +34,8 @@ RSpec.describe(Flags::ToggleFlag) do
end
context "when everything's ok" do
after { flag.reload.update!(enabled: true) }
it { is_expected.to run_successfully }
it "toggles the flag" do

View File

@ -36,6 +36,8 @@ RSpec.describe(Flags::UpdateFlag) do
let(:enabled) { false }
let(:auto_action_type) { true }
after { flag.destroy! }
context "when contract is invalid" do
let(:name) { nil }
@ -70,6 +72,8 @@ RSpec.describe(Flags::UpdateFlag) do
let!(:flag_2) { Fabricate(:flag, name:) }
it { is_expected.to fail_a_policy(:unique_name) }
after { flag_2.destroy! }
end
context "when everything's ok" do