mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 21:45:26 +08:00
FIX: Form template limit validation (#28791)
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user