Skip to content

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

DEV: Set limits for text fields on BadgeGrouping

Loïc Guitautb81c13280acf
diff --git a/app/models/badge_grouping.rb b/app/models/badge_grouping.rb
index c0afcbdbb10..cb60e4f715c 100644
--- a/app/models/badge_grouping.rb
+++ b/app/models/badge_grouping.rb
@@ -9,6 +9,9 @@ class BadgeGrouping < ActiveRecord::Base
has_many :badges
+ validates :name, length: { maximum: 100 }
+ validates :description, length: { maximum: 500 }
+
def system?
id && id <= 5
end
diff --git a/spec/models/badge_grouping_spec.rb b/spec/models/badge_grouping_spec.rb
new file mode 100644
index 00000000000..58b5dbdb343
--- /dev/null
+++ b/spec/models/badge_grouping_spec.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+require "rails_helper"
+
+RSpec.describe BadgeGrouping, type: :model do
+ it { is_expected.to validate_length_of(:name).is_at_most(100) }
+ it { is_expected.to validate_length_of(:description).is_at_most(500) }
+end