mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 19:53:41 +08:00
FIX: custom flag name should be unique (#28869)
Validation to ensure that the custom flag name is unique.
This commit is contained in:

committed by
GitHub

parent
042bfeac66
commit
c5a024f8df
@ -24,6 +24,15 @@ RSpec.describe(Flags::CreateFlag) do
|
||||
it { is_expected.to fail_a_policy(:invalid_access) }
|
||||
end
|
||||
|
||||
context "when title is not unique" do
|
||||
fab!(:current_user) { Fabricate(:admin) }
|
||||
fab!(:flag) { Fabricate(:flag, name: "custom flag name") }
|
||||
|
||||
it { is_expected.to fail_a_policy(:unique_name) }
|
||||
|
||||
after { Flag.destroy_by(name: "custom flag name") }
|
||||
end
|
||||
|
||||
context "when applies to is invalid" do
|
||||
fab!(:current_user) { Fabricate(:admin) }
|
||||
let(:applies_to) { ["User"] }
|
||||
|
@ -43,6 +43,15 @@ RSpec.describe(Flags::UpdateFlag) do
|
||||
it { is_expected.to fail_a_contract }
|
||||
end
|
||||
|
||||
context "when title is not unique" do
|
||||
fab!(:current_user) { Fabricate(:admin) }
|
||||
fab!(:flag_2) { Fabricate(:flag, name: "edited custom flag name") }
|
||||
|
||||
it { is_expected.to fail_a_policy(:unique_name) }
|
||||
|
||||
after { Flag.destroy_by(name: "edited custom flag name") }
|
||||
end
|
||||
|
||||
context "when title is too long" do
|
||||
fab!(:current_user) { Fabricate(:admin) }
|
||||
let(:name) { "a" * 201 }
|
||||
|
Reference in New Issue
Block a user