summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-02-09 17:59:47 +0100
committerRémy Coutable <remy@rymai.me>2016-02-09 18:15:35 +0100
commitb3635ee46a1e62d72ce84871e2a5984e6eabfbdf (patch)
treeda9f077646a7baa0b0aee9f7c2412fe271ac9814
parentb34963bc125d11af7b9c993d1233258f084e580d (diff)
downloadgitlab-ce-streamline-email-validation.tar.gz
Re-add EmailValidator to avoid the repetition of format: { with: Devise.email_regexp }streamline-email-validation
-rw-r--r--app/models/application_setting.rb2
-rw-r--r--app/models/email.rb2
-rw-r--r--app/models/member.rb3
-rw-r--r--app/models/user.rb4
-rw-r--r--app/validators/email_validator.rb5
5 files changed, 10 insertions, 6 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb
index ac6653f5d50..269056e0e77 100644
--- a/app/models/application_setting.rb
+++ b/app/models/application_setting.rb
@@ -71,7 +71,7 @@ class ApplicationSetting < ActiveRecord::Base
url: true
validates :admin_notification_email,
- format: { with: Devise.email_regexp },
+ email: true,
allow_blank: true
validates :two_factor_grace_period,
diff --git a/app/models/email.rb b/app/models/email.rb
index daa259ee2d2..b323d1edd10 100644
--- a/app/models/email.rb
+++ b/app/models/email.rb
@@ -15,7 +15,7 @@ class Email < ActiveRecord::Base
belongs_to :user
validates :user_id, presence: true
- validates :email, presence: true, uniqueness: true, format: { with: Devise.email_regexp }
+ validates :email, presence: true, uniqueness: true, email: true
validate :unique_email, if: ->(email) { email.email_changed? }
before_validation :cleanup_email
diff --git a/app/models/member.rb b/app/models/member.rb
index 0b6785ddbc5..ca08007b7eb 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -38,8 +38,7 @@ class Member < ActiveRecord::Base
presence: {
if: :invite?
},
- format: {
- with: Devise.email_regexp,
+ email: {
allow_nil: true
},
uniqueness: {
diff --git a/app/models/user.rb b/app/models/user.rb
index edda0ebef86..9fe94b13e52 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -146,8 +146,8 @@ class User < ActiveRecord::Base
# Validations
#
validates :name, presence: true
- validates :notification_email, presence: true, format: { with: Devise.email_regexp }
- validates :public_email, presence: true, uniqueness: true, format: { with: Devise.email_regexp }, allow_blank: true
+ validates :notification_email, presence: true, email: true
+ validates :public_email, presence: true, uniqueness: true, email: true, allow_blank: true
validates :bio, length: { maximum: 255 }, allow_blank: true
validates :projects_limit, presence: true, numericality: { greater_than_or_equal_to: 0 }
validates :username,
diff --git a/app/validators/email_validator.rb b/app/validators/email_validator.rb
new file mode 100644
index 00000000000..aab07a7ece4
--- /dev/null
+++ b/app/validators/email_validator.rb
@@ -0,0 +1,5 @@
+class EmailValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ record.errors.add(attribute, :invalid) unless value =~ Devise.email_regexp
+ end
+end