Commit 64373744 authored by Robert May's avatar Robert May

Merge branch 'use-same-email-validation-on-users-and-emails' into 'master'

Use the same email validation for User and Email

See merge request gitlab-org/gitlab!77785
parents d3bae310 866a5fa0
......@@ -6,8 +6,8 @@ class Email < ApplicationRecord
belongs_to :user, optional: false
validates :email, presence: true, uniqueness: true
validate :validate_email_format
validates :email, presence: true, uniqueness: true, devise_email: true
validate :unique_email, if: ->(email) { email.email_changed? }
scope :confirmed, -> { where.not(confirmed_at: nil) }
......@@ -33,10 +33,6 @@ class Email < ApplicationRecord
self.errors.add(:email, 'has already been taken') if primary_email_of_another_user?
end
def validate_email_format
self.errors.add(:email, I18n.t(:invalid, scope: 'valid_email.validations.email')) unless ValidateEmail.valid?(self.email)
end
# once email is confirmed, update the gpg signatures
def update_invalid_gpg_signatures
user.update_invalid_gpg_signatures if confirmed?
......
......@@ -16,7 +16,7 @@ RSpec.describe Gitlab::UsageDataNonSqlMetrics do
described_class.uncached_data
end
expect(recorder.count).to eq(63)
expect(recorder.count).to eq(65)
end
end
end
......@@ -49,7 +49,7 @@ RSpec.describe Profiles::EmailsController do
end
context 'when email address is invalid' do
let(:email) { 'invalid.@example.com' }
let(:email) { 'invalid@@example.com' }
it 'does not send an email confirmation' do
expect { subject }.not_to change { ActionMailer::Base.deliveries.size }
......
......@@ -44,7 +44,7 @@ RSpec.describe 'Profile > Emails' do
end
it 'does not add an invalid email' do
fill_in('Email', with: 'test.@example.com')
fill_in('Email', with: 'test@@example.com')
click_button('Add email address')
email = user.emails.find_by(email: email)
......
......@@ -10,7 +10,7 @@ RSpec.describe Email do
end
describe 'validations' do
it_behaves_like 'an object with RFC3696 compliant email-formatted attributes', :email do
it_behaves_like 'an object with email-formatted attributes', :email do
subject { build(:email) }
end
......
......@@ -436,7 +436,7 @@ RSpec.describe User do
subject { build(:user) }
end
it_behaves_like 'an object with RFC3696 compliant email-formatted attributes', :public_email, :notification_email do
it_behaves_like 'an object with email-formatted attributes', :public_email, :notification_email do
subject { create(:user).tap { |user| user.emails << build(:email, email: email_value, confirmed_at: Time.current) } }
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment