From 5b37ac3adb15861e75a6752473a2e2e32e2aa340 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 7 Mar 2021 21:15:33 -0600 Subject: [PATCH] favgroups: validate that name is present. --- app/models/favorite_group.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/favorite_group.rb b/app/models/favorite_group.rb index 5a0c07190..f831172ea 100644 --- a/app/models/favorite_group.rb +++ b/app/models/favorite_group.rb @@ -1,9 +1,12 @@ class FavoriteGroup < ApplicationRecord - validates_uniqueness_of :name, :case_sensitive => false, :scope => :creator_id - validates_format_of :name, :with => /\A[^,]+\Z/, :message => "cannot have commas" belongs_to :creator, class_name: "User" + before_validation :normalize_name before_validation :strip_name + + validates :name, presence: true + validates :name, uniqueness: { case_sensitive: false, scope: :creator_id } + validates :name, format: { without: /,/, message: "cannot have commas" } validate :creator_can_create_favorite_groups, :on => :create validate :validate_number_of_posts validate :validate_posts