Add validations
This commit is contained in:
parent
ad1478f6f5
commit
db94693868
6 changed files with 7 additions and 8 deletions
|
@ -39,13 +39,11 @@ class Account < ApplicationRecord
|
|||
|
||||
validates :public_name, allow_nil: true, length: { in: 1..255 }
|
||||
|
||||
validates :biography,
|
||||
allow_nil: true,
|
||||
good_big_text: true
|
||||
validates :biography, allow_nil: true, good_big_text: true
|
||||
|
||||
validates :avatar, allow_nil: true, image: true
|
||||
|
||||
validates :timezone, presence: true, timezone: true
|
||||
validates :timezone, timezone: true
|
||||
|
||||
validate :contact_list_corresponds_person
|
||||
validate :person_corresponds_contact_list
|
||||
|
|
|
@ -42,7 +42,7 @@ class FederalSubject < ApplicationRecord
|
|||
uniqueness: true,
|
||||
numericality: { only_integer: true, greater_than: 0 }
|
||||
|
||||
validates :timezone, presence: true, timezone: true
|
||||
validates :timezone, timezone: true
|
||||
|
||||
validate :english_name_looks_realistic
|
||||
validate :native_name_looks_realistic
|
||||
|
|
|
@ -22,9 +22,7 @@ class Session < ApplicationRecord
|
|||
|
||||
validates :ip_address, presence: true
|
||||
|
||||
validates :user_agent,
|
||||
allow_nil: true,
|
||||
good_big_text: true
|
||||
validates :user_agent, allow_nil: true, good_big_text: true
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ class CodenameValidator < ApplicationEachValidator
|
|||
MAX = 36
|
||||
|
||||
def perform
|
||||
error! :blank if value.to_s.blank?
|
||||
error! :codename unless CODENAME_RE.match? value
|
||||
error! :too_short, count: MIN if value.to_s.length < MIN
|
||||
error! :too_long, count: MAX if value.to_s.length > MAX
|
||||
|
|
|
@ -5,6 +5,7 @@ class GoodTextValidator < ApplicationEachValidator
|
|||
GOOD_TEXT_RE = /\A[^\s](.*[^\s])?\z/.freeze
|
||||
|
||||
def perform
|
||||
error! :blank if value.to_s.blank?
|
||||
error! :good_text unless GOOD_TEXT_RE.match? value
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,7 @@ class TimezoneValidator < ApplicationEachValidator
|
|||
TIMEZONE_RE = /\A-?\d\d:\d\d:00\z/.freeze
|
||||
|
||||
def perform
|
||||
error! :blank if value.to_s.blank?
|
||||
error! :timezone unless TIMEZONE_RE.match? value
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue