FIX: Form template limit validation (#28791)

This commit is contained in:
Keegan George
2024-09-10 08:11:44 -07:00
committed by GitHub
parent 0a994a9221
commit f2059bf15f
4 changed files with 57 additions and 14 deletions

View File

@ -11,6 +11,48 @@ RSpec.describe FormTemplate, type: :model do
expect(described_class.count).to eq(1)
end
context "when length validations set in SiteSetting" do
before do
SiteSetting.max_form_template_content_length = 50
SiteSetting.max_form_template_title_length = 5
end
it "can't exceed max title length" do
t = Fabricate.build(:form_template, name: "Bug Report", template: "- type: input\n id: name")
expect(t.save).to eq(false)
expect(t.errors.full_messages.first).to include(
"Name #{I18n.t("errors.messages.too_long", count: SiteSetting.max_form_template_title_length)}",
)
end
it "can't exceed max content length" do
t =
Fabricate.build(
:form_template,
name: "Bug",
template: "- type: input\n id: name-that-is-really-long-to-make-the-template-longer",
)
expect(t.save).to eq(false)
expect(t.errors.full_messages.first).to include(
"Template #{I18n.t("errors.messages.too_long", count: SiteSetting.max_form_template_content_length)}",
)
end
it "should update validation limits when the site setting has been changed" do
SiteSetting.max_form_template_content_length = 100
SiteSetting.max_form_template_title_length = 100
t =
Fabricate.build(
:form_template,
name: "Bug Report",
template: "- type: input\n id: name-that-is-really-long-to-make-the-template-longer",
)
expect(t.save).to eq(true)
end
end
it "can't have an invalid yaml template" do
template = "- type: checkbox\nattributes; bad"
t = Fabricate.build(:form_template, name: "Feature Request", template: template)