Skip to content

A platform for community discussion. Free, open, simple.

DEV: set limits for text fields on groups

Loïc Guitauta89b3c27aaf9
diff --git a/app/models/group.rb b/app/models/group.rb
index 741ae34e265..e3e671431aa 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -89,6 +89,10 @@ class Group < ActiveRecord::Base
validate :incoming_email_validator
validate :can_allow_membership_requests, if: :allow_membership_requests
validate :validate_grant_trust_level, if: :will_save_change_to_grant_trust_level?
+ validates :automatic_membership_email_domains, length: { maximum: 100 }
+ validates :bio_raw, length: { maximum: 3000 }
+ validates :membership_request_template, length: { maximum: 500 }
+ validates :full_name, length: { maximum: 100 }
AUTO_GROUPS = {
everyone: 0,
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index bb876b7bb21..d4fe873d05a 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -6,6 +6,14 @@ RSpec.describe Group do
let(:group) { Fabricate(:group) }
describe "Validations" do
+ it { is_expected.to allow_value("#{"a" * 96}.com").for(:automatic_membership_email_domains) }
+ it do
+ is_expected.not_to allow_value("#{"a" * 97}.com").for(:automatic_membership_email_domains)
+ end
+ it { is_expected.to validate_length_of(:bio_raw).is_at_most(3000) }
+ it { is_expected.to validate_length_of(:membership_request_template).is_at_most(500) }
+ it { is_expected.to validate_length_of(:full_name).is_at_most(100) }
+
describe "#grant_trust_level" do
describe "when trust level is not valid" do
it "should not be valid" do