1
0
Fork 0

Add validations

This commit is contained in:
Alex Kotov 2019-09-30 16:30:19 +05:00
parent ad1478f6f5
commit db94693868
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
6 changed files with 7 additions and 8 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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