FIX: Don't downcase group name.

This commit is contained in:
Guo Xiang Tan 2018-05-07 14:02:11 +08:00
parent aa0d32231c
commit ad833c4485
2 changed files with 5 additions and 4 deletions

View File

@ -598,12 +598,13 @@ class Group < ActiveRecord::Base
def name_format_validator
self.name.strip!
self.name.downcase!
UsernameValidator.perform_validation(self, 'name') || begin
if will_save_change_to_name? && name_was&.downcase != self.name
name_lower = self.name.downcase
if self.will_save_change_to_name? && self.name_was&.downcase != name_lower
existing = Group.exec_sql(
User::USERNAME_EXISTS_SQL, username: self.name
User::USERNAME_EXISTS_SQL, username: name_lower
).values.present?
if existing

View File

@ -21,7 +21,7 @@ describe Group do
end
end
describe '#username' do
describe '#name' do
context 'when a user with a similar name exists' do
it 'should not be valid' do
new_group = Fabricate.build(:group, name: admin.username.upcase)