From db946938689e20aa91a8720a5004886e79bb0f31 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Mon, 30 Sep 2019 16:30:19 +0500 Subject: [PATCH] Add validations --- app/models/account.rb | 6 ++---- app/models/federal_subject.rb | 2 +- app/models/session.rb | 4 +--- app/validators/codename_validator.rb | 1 + app/validators/good_text_validator.rb | 1 + app/validators/timezone_validator.rb | 1 + 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index c185c22..125eb5e 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -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 diff --git a/app/models/federal_subject.rb b/app/models/federal_subject.rb index 78200b7..e760deb 100644 --- a/app/models/federal_subject.rb +++ b/app/models/federal_subject.rb @@ -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 diff --git a/app/models/session.rb b/app/models/session.rb index 1b5ba86..a018365 100644 --- a/app/models/session.rb +++ b/app/models/session.rb @@ -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 diff --git a/app/validators/codename_validator.rb b/app/validators/codename_validator.rb index 5e758a6..a2fabf4 100644 --- a/app/validators/codename_validator.rb +++ b/app/validators/codename_validator.rb @@ -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 diff --git a/app/validators/good_text_validator.rb b/app/validators/good_text_validator.rb index de93548..45bb186 100644 --- a/app/validators/good_text_validator.rb +++ b/app/validators/good_text_validator.rb @@ -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 diff --git a/app/validators/timezone_validator.rb b/app/validators/timezone_validator.rb index fac757a..22c80f1 100644 --- a/app/validators/timezone_validator.rb +++ b/app/validators/timezone_validator.rb @@ -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