A platform for community discussion. Free, open, simple.
FIX: flag valid type inclusion should be lambda (#28030)
Krzysztof Kotlareke020888b0a30
diff --git a/app/services/flags/create_flag.rb b/app/services/flags/create_flag.rbindex 0db5616b8c4..dab3e8c13b8 100644--- a/app/services/flags/create_flag.rb+++ b/app/services/flags/create_flag.rb@@ -22,7 +22,7 @@ class Flags::CreateFlagvalidates :description, presence: truevalidates :name, length: { maximum: Flag::MAX_NAME_LENGTH }validates :description, length: { maximum: Flag::MAX_DESCRIPTION_LENGTH }- validates :applies_to, inclusion: { in: Flag.valid_applies_to_types }, allow_nil: false+ validates :applies_to, inclusion: { in: -> { Flag.valid_applies_to_types } }, allow_nil: falseendprivatediff --git a/app/services/flags/update_flag.rb b/app/services/flags/update_flag.rbindex 3ccf6f0a7d0..b04e0e99b2e 100644--- a/app/services/flags/update_flag.rb+++ b/app/services/flags/update_flag.rb@@ -24,7 +24,7 @@ class Flags::UpdateFlagvalidates :description, presence: truevalidates :name, length: { maximum: Flag::MAX_NAME_LENGTH }validates :description, length: { maximum: Flag::MAX_DESCRIPTION_LENGTH }- validates :applies_to, inclusion: { in: Flag.valid_applies_to_types }, allow_nil: false+ validates :applies_to, inclusion: { in: -> { Flag.valid_applies_to_types } }, allow_nil: falseendprivatediff --git a/spec/services/flags/create_flag_spec.rb b/spec/services/flags/create_flag_spec.rbindex 0a99def3f8a..2a411697d57 100644--- a/spec/services/flags/create_flag_spec.rb+++ b/spec/services/flags/create_flag_spec.rb@@ -61,7 +61,14 @@ RSpec.describe(Flags::CreateFlag) docontext "when user is allowed to perform the action" dofab!(:current_user) { Fabricate(:admin) }+ let(:applies_to) { ["Topic::Custom"] }+ before do+ DiscoursePluginRegistry.register_flag_applies_to_type(+ "Topic::Custom",+ OpenStruct.new(enabled?: true),+ )+ endafter { Flag.destroy_by(name: "custom flag name") }it "sets the service result as successful" do@@ -73,7 +80,7 @@ RSpec.describe(Flags::CreateFlag) doflag = Flag.lastexpect(flag.name).to eq("custom flag name")expect(flag.description).to eq("custom flag description")- expect(flag.applies_to).to eq(["Topic"])+ expect(flag.applies_to).to eq(["Topic::Custom"])expect(flag.require_message).to be trueexpect(flag.enabled).to be trueend@@ -83,7 +90,7 @@ RSpec.describe(Flags::CreateFlag) doexpect(UserHistory.last).to have_attributes(custom_type: "create_flag",details:- "name: custom flag name\ndescription: custom flag description\napplies_to: [\"Topic\"]\nrequire_message: true\nenabled: true",+ "name: custom flag name\ndescription: custom flag description\napplies_to: [\"Topic::Custom\"]\nrequire_message: true\nenabled: true",)endend