FIX: EmailValidator needs to validate format of email.

This commit is contained in:
Guo Xiang Tan
2020-06-03 10:13:25 +08:00
parent 1b5a505930
commit 062db10c52
7 changed files with 24 additions and 11 deletions

View File

@@ -18,7 +18,7 @@ class Invite < ActiveRecord::Base
has_many :topic_invites
has_many :topics, through: :topic_invites, source: :topic
validates_presence_of :invited_by_id
validates :email, email: true, format: { with: EmailValidator.email_regex }, allow_blank: true
validates :email, email: true, allow_blank: true
before_create do
self.invite_key ||= SecureRandom.hex

View File

@@ -11,8 +11,7 @@ class UserEmail < ActiveRecord::Base
before_validation :strip_downcase_email
validates :email, presence: true
validates :email, email: true, format: { with: EmailValidator.email_regex },
if: :validate_email?
validates :email, email: true, if: :validate_email?
validates :primary, uniqueness: { scope: [:user_id] }, if: [:user_id, :primary]
validate :user_id_not_changed, if: :primary