summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-01-04 17:20:38 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-01-04 17:20:38 +0000
commite586492e48ab9fd9a2cdf21f8d9ff686ac6e5abf (patch)
tree78baf59027a2b4cfe16e7bc23a79df58ce364ee5
parent7e034a7f72e6a47bfb56b1b00ee510b5e03baab5 (diff)
parentfd178c1e7d23b0bf96565ae5177485e847c9271d (diff)
downloadgitlab-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.rb5
-rw-r--r--spec/models/user_spec.rb2
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