mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
5257c80064
This patch sets some limits on custom fields: - an entity can’t have more than 100 custom fields defined on it - a custom field can’t hold a value greater than 10,000,000 characters The current implementation of custom fields is relatively complex and does an upsert in SQL at some point, thus preventing to simply add an `ActiveRecord` validation on the custom field model without having to rewrite a part of the existing logic. That’s one of the reasons this patch is implementing validations in the `HasCustomField` module adding them to the model including the module.
28 lines
801 B
Ruby
28 lines
801 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.shared_examples_for "it has custom fields" do
|
|
let(:record) { described_class.new }
|
|
|
|
describe "Max number of custom fields" do
|
|
let(:custom_fields) { (1..101).to_a.product(["value"]).to_h }
|
|
|
|
before { record.custom_fields = custom_fields }
|
|
|
|
it "can't have more than 100 custom fields" do
|
|
expect(record).to be_invalid
|
|
expect(record.errors[:base]).to include(/Maximum number.*\(100\)/)
|
|
end
|
|
end
|
|
|
|
describe "Max length of a custom field" do
|
|
let(:bad_value) { "a" * 10_000_001 }
|
|
|
|
before { record.custom_fields[:my_custom_field] = bad_value }
|
|
|
|
it "can't have more than 10,000,000 characters" do
|
|
expect(record).to be_invalid
|
|
expect(record.errors[:base]).to include(/Maximum length.*\(10000000\)/)
|
|
end
|
|
end
|
|
end
|