<commit_before>class UniqueUserNameForBulkUploadValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    
    account = record.bulk_upload.account
    record.errors[:email] << 'must be unique' if account.employees.where(:user_name => value).count() > 0
    
  end
end<commit_msg>improvements to unique user name validator<commit_after>class UniqueUserNameForBulkUploadValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    
    return if record.first_name.blank? || record.last_name.blank?
    
    account = record.bulk_upload.account
    
    # checks for duplicates in existing and proposed new employees
    
    if account.employees.where(
        :user_name => value
       ).count() > 0 || 
       record.bulk_upload.records.where(
         'LOWER(first_name) = :first_name AND LOWER(last_name) = :last_name',
         { 
          :first_name => record.first_name.downcase,
          :last_name => record.last_name.downcase 
         }
       ).where("id <> #{record.id}").count() > 0
    
      record.errors[:user_name] << 'has already been taken'
    end
    
  end
end
{'fraction_non_alphanumeric': 0.10383944153577661, 'fraction_numerical': 0.002617801047120419, 'mean_word_length': 3.0964285714285715, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '826323', 'n_tokens_mistral': 352, 'n_tokens_neox': 336, 'n_words': 72}