diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-01-04 17:20:38 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-01-04 17:20:38 +0000 |
commit | e586492e48ab9fd9a2cdf21f8d9ff686ac6e5abf (patch) | |
tree | 78baf59027a2b4cfe16e7bc23a79df58ce364ee5 | |
parent | 7e034a7f72e6a47bfb56b1b00ee510b5e03baab5 (diff) | |
parent | fd178c1e7d23b0bf96565ae5177485e847c9271d (diff) | |
download | gitlab-ce-e586492e48ab9fd9a2cdf21f8d9ff686ac6e5abf.tar.gz |
Merge branch 'rs-issue-201' into 'master'
Prevent duplicate "username has already been taken" validation message
Closes #201 - two-year-old bug, woo! :boom: :tada:
See merge request !2279
-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 |