diff options
author | Robert Speicher <rspeicher@gmail.com> | 2016-01-02 19:53:45 -0500 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-01-02 20:03:28 -0500 |
commit | fd178c1e7d23b0bf96565ae5177485e847c9271d (patch) | |
tree | e1c01bb9497e0811cf98c43fcd74d9e1935bde2e | |
parent | de6b6ccc421776891085c5c41e90d33a01e3ac30 (diff) | |
download | gitlab-ce-fd178c1e7d23b0bf96565ae5177485e847c9271d.tar.gz |
Prevent duplicate "username has already been taken" validation messagers-issue-201
Closes #201 - two-year-old bug, woo! :boom: :tada:
-rw-r--r-- | app/models/user.rb | 5 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 2 |
2 files changed, 5 insertions, 2 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index df87f3b79bd..20f907e4347 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -352,10 +352,13 @@ class User < ActiveRecord::Base end def namespace_uniq + # Return early if username already failed the first uniqueness validation + return if self.errors[:username].include?('has already been taken') + namespace_name = self.username existing_namespace = Namespace.by_path(namespace_name) if existing_namespace && existing_namespace != self.namespace - self.errors.add :username, "already exists" + self.errors.add(:username, 'has already been taken') end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 2f184bbaf92..a16161e673e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -106,7 +106,7 @@ describe User, models: true do end it 'validates uniqueness' do - expect(subject).to validate_uniqueness_of(:username) + expect(subject).to validate_uniqueness_of(:username).case_insensitive end end |