BigW Consortium Gitlab

Commit fd178c1e by Robert Speicher

Prevent duplicate "username has already been taken" validation message

Closes #201 - two-year-old bug, woo! 💥 🎉
parent de6b6ccc
...@@ -352,10 +352,13 @@ class User < ActiveRecord::Base ...@@ -352,10 +352,13 @@ class User < ActiveRecord::Base
end end
def namespace_uniq 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 namespace_name = self.username
existing_namespace = Namespace.by_path(namespace_name) existing_namespace = Namespace.by_path(namespace_name)
if existing_namespace && existing_namespace != self.namespace if existing_namespace && existing_namespace != self.namespace
self.errors.add :username, "already exists" self.errors.add(:username, 'has already been taken')
end end
end end
......
...@@ -106,7 +106,7 @@ describe User, models: true do ...@@ -106,7 +106,7 @@ describe User, models: true do
end end
it 'validates uniqueness' do it 'validates uniqueness' do
expect(subject).to validate_uniqueness_of(:username) expect(subject).to validate_uniqueness_of(:username).case_insensitive
end end
end end
......
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