diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | app/models/user.rb | 4 | ||||
-rw-r--r-- | spec/controllers/admin/users_controller_spec.rb | 11 |
3 files changed, 15 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 447a5614e75..09d1de30672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Please view this file on the master branch, on stable branches it's out of date. - Fix mobile layout issues in admin user overview page !7087 - Fix HipChat notifications rendering (airatshigapov, eisnerd) - Add hover to trash icon in notes !7008 (blackst0ne) + - Only show one error message for an invalid email !5905 (lycoperdon) - Fix sidekiq stats in admin area (blackst0ne) - Removed delete branch tooltip !6954 - Escape ref and path for relative links !6050 (winniehell) diff --git a/app/models/user.rb b/app/models/user.rb index 9e76df63d31..e2a97c3a757 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 } diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 33fe3c73822..2ab2ca1b667 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -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) |