A platform for community discussion. Free, open, simple.
DEV: Add comments in flags specs
Loïc Guitautd991378218c6
diff --git a/spec/services/flags/create_flag_spec.rb b/spec/services/flags/create_flag_spec.rbindex ea530943e59..1da6cbbb212 100644--- a/spec/services/flags/create_flag_spec.rb+++ b/spec/services/flags/create_flag_spec.rb@@ -40,9 +40,11 @@ RSpec.describe(Flags::CreateFlag) docontext "when name is not unique" dolet!(:flag) { Fabricate(:flag, name:) }- it { is_expected.to fail_a_policy(:unique_name) }-+ # DO NOT REMOVE: flags have side effects and their state will leak to+ # other examples otherwise.after { flag.destroy! }++ it { is_expected.to fail_a_policy(:unique_name) }endcontext "when everything's ok" do@@ -56,6 +58,8 @@ RSpec.describe(Flags::CreateFlag) do)end+ # DO NOT REMOVE: flags have side effects and their state will leak to+ # other examples otherwise.after { flag.destroy! }it { is_expected.to run_successfully }diff --git a/spec/services/flags/destroy_flag_spec.rb b/spec/services/flags/destroy_flag_spec.rbindex cb2e9e3c9bc..028b5fa0990 100644--- a/spec/services/flags/destroy_flag_spec.rb+++ b/spec/services/flags/destroy_flag_spec.rb@@ -4,35 +4,35 @@ RSpec.describe(Flags::DestroyFlag) dosubject(:result) { described_class.call(**params, **dependencies) }fab!(:current_user) { Fabricate(:admin) }+ fab!(:flag)- let(:flag) { Fabricate(:flag) }let(:params) { { id: flag_id } }let(:dependencies) { { guardian: current_user.guardian } }let(:flag_id) { flag.id }+ # DO NOT REMOVE: flags have side effects and their state will leak to+ # other examples otherwise.+ after { flag.destroy! }+context "when model is not found" do- after { flag.destroy! }let(:flag_id) { 0 }it { is_expected.to fail_to_find_a_model(:flag) }endcontext "when the flag is a system one" do- after { flag.destroy! }let(:flag) { Flag.first }it { is_expected.to fail_a_policy(:not_system) }endcontext "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) }endcontext "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) }diff --git a/spec/services/flags/reorder_flag_spec.rb b/spec/services/flags/reorder_flag_spec.rbindex 2e5c594616d..e8352506ab4 100644--- a/spec/services/flags/reorder_flag_spec.rb+++ b/spec/services/flags/reorder_flag_spec.rb@@ -42,9 +42,9 @@ RSpec.describe(Flags::ReorderFlag) doendcontext "when everything's ok" do- after do- described_class.call(flag_id: flag.id, guardian: current_user.guardian, direction: "down")- end+ # DO NOT REMOVE: flags have side effects and their state will leak to+ # other examples otherwise.+ after { described_class.call(**params.merge(direction: "down"), **dependencies) }it { is_expected.to run_successfully }diff --git a/spec/services/flags/toggle_flag_spec.rb b/spec/services/flags/toggle_flag_spec.rbindex 871e5a36441..3d21bd733b5 100644--- a/spec/services/flags/toggle_flag_spec.rb+++ b/spec/services/flags/toggle_flag_spec.rb@@ -9,12 +9,16 @@ RSpec.describe(Flags::ToggleFlag) dosubject(:result) { described_class.call(**params, **dependencies) }fab!(:current_user) { Fabricate(:admin) }+ fab!(:flag)- let(:flag) { Fabricate(:flag) }let(:flag_id) { flag.id }let(:params) { { flag_id: flag_id } }let(:dependencies) { { guardian: current_user.guardian } }+ # DO NOT REMOVE: flags have side effects and their state will leak to+ # other examples otherwise.+ after { flag.destroy! }+context "when user is not allowed to perform the action" dofab!(:current_user) { Fabricate(:user) }@@ -34,8 +38,6 @@ RSpec.describe(Flags::ToggleFlag) doendcontext "when everything's ok" do- after { flag.reload.update!(enabled: true) }-it { is_expected.to run_successfully }it "toggles the flag" dodiff --git a/spec/services/flags/update_flag_spec.rb b/spec/services/flags/update_flag_spec.rbindex b0d240e0ea8..c7bc2452678 100644--- a/spec/services/flags/update_flag_spec.rb+++ b/spec/services/flags/update_flag_spec.rb@@ -14,8 +14,8 @@ RSpec.describe(Flags::UpdateFlag) dosubject(:result) { described_class.call(**params, **dependencies) }fab!(:current_user) { Fabricate(:admin) }+ fab!(:flag)- let(:flag) { Fabricate(:flag) }let(:params) do{id: flag_id,@@ -36,6 +36,8 @@ RSpec.describe(Flags::UpdateFlag) dolet(:enabled) { false }let(:auto_action_type) { true }+ # DO NOT REMOVE: flags have side effects and their state will leak to+ # other examples otherwise.after { flag.destroy! }context "when contract is invalid" do@@ -71,9 +73,11 @@ RSpec.describe(Flags::UpdateFlag) docontext "when title is not unique" dolet!(:flag_2) { Fabricate(:flag, name:) }- it { is_expected.to fail_a_policy(:unique_name) }-+ # DO NOT REMOVE: flags have side effects and their state will leak to+ # other examples otherwise.after { flag_2.destroy! }++ it { is_expected.to fail_a_policy(:unique_name) }endcontext "when everything's ok" do