Commit e586492e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'rs-issue-201' into 'master'

Prevent duplicate "username has already been taken" validation message

Closes #201 - two-year-old bug, woo! 💥 🎉

See merge request !2279
parents 7e034a7f fd178c1e
......@@ -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