diff --git a/app/models/group.rb b/app/models/group.rb index 9f049c8821a..53f9d6a3cae 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -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 diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index d4d6e5a954b..c4c34bc23f9 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -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)