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
This commit is contained in:
commit
e586492e48
|
@ -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
|
||||||
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue