Commit fd178c1e authored by Robert Speicher's avatar 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
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
......
......@@ -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
......
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