Commit 36ec5eaf authored by Steve Halasz's avatar Steve Halasz

Only show one error message for an invalid email

If notification_email is blank, it's set from email. If an admin
attempted to create a user with an invalid email, an error would be
displayed for both fields. Only validate the notification_email if it's
different from email.
parent 132e3f54
......@@ -93,8 +93,10 @@ class User < ActiveRecord::Base
#
# Validations
#
# Note: devise :validatable above adds validations for :email and :password
validates :name, presence: true
validates :notification_email, presence: true, email: true
validates :notification_email, presence: true
validates :notification_email, email: true, if: ->(user) { user.notification_email != user.email }
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 }
......
......@@ -114,6 +114,17 @@ describe Admin::UsersController do
end
end
describe 'POST create' do
it 'creates the user' do
expect{ post :create, user: attributes_for(:user) }.to change{ User.count }.by(1)
end
it 'shows only one error message for an invalid email' do
post :create, user: attributes_for(:user, email: 'bogus')
expect(assigns[:user].errors).to contain_exactly("Email is invalid")
end
end
describe 'POST update' do
context 'when the password has changed' do
def update_password(user, password, password_confirmation = nil)
......
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