<commit_before>require 'digest/sha1'

class User < ActiveRecord::Base
  default_scope :conditions => {:deleted_at => nil}
  attr_accessible :username, :password, :first_name, :last_name, :email, :title, :dept, :notes, :image
  attr_reader :password

  has_many :instances, :foreign_key => :owner_id

  has_attached_file :image, :styles => { :original => "", :icon => "100x100>" }

  validates_presence_of :username, :first_name, :last_name, :email
  validate :uniqueness_of_non_deleted_username
  validates_format_of :email, :with => /[\w\.-]+(\+[\w-]*)?@([\w-]+\.)+[\w-]+/
  validates_format_of :username, :with => /^\S+$/
  validates_presence_of :password, :unless => :password_digest?
  validates_length_of :password, :minimum => 6, :maximum => 256, :if => :password
  validates_length_of :username, :first_name, :last_name, :email, :title, :dept, :maximum => 256
  validates_length_of :notes, :maximum => 4096

  def uniqueness_of_non_deleted_username
    if self.username
      other_user = User.where("lower(users.username) = ?", self.username.downcase)
      other_user = other_user.where("id != ?", self.id) if self.id
      if other_user.present?
        errors.add(:username, :taken)
      end
    end
  end<commit_msg>Fix integration test; image should not be mass assignable through UsersController#update<commit_after>require 'digest/sha1'

class User < ActiveRecord::Base
  default_scope :conditions => {:deleted_at => nil}
  attr_accessible :username, :password, :first_name, :last_name, :email, :title, :dept, :notes
  attr_reader :password

  has_many :instances, :foreign_key => :owner_id

  has_attached_file :image, :styles => { :original => "", :icon => "100x100>" }

  validates_presence_of :username, :first_name, :last_name, :email
  validate :uniqueness_of_non_deleted_username
  validates_format_of :email, :with => /[\w\.-]+(\+[\w-]*)?@([\w-]+\.)+[\w-]+/
  validates_format_of :username, :with => /^\S+$/
  validates_presence_of :password, :unless => :password_digest?
  validates_length_of :password, :minimum => 6, :maximum => 256, :if => :password
  validates_length_of :username, :first_name, :last_name, :email, :title, :dept, :maximum => 256
  validates_length_of :notes, :maximum => 4096

  def uniqueness_of_non_deleted_username
    if self.username
      other_user = User.where("lower(users.username) = ?", self.username.downcase)
      other_user = other_user.where("id != ?", self.id) if self.id
      if other_user.present?
        errors.add(:username, :taken)
      end
    end
  end
{'fraction_non_alphanumeric': 0.15445544554455445, 'fraction_numerical': 0.014257425742574258, 'mean_word_length': 4.6891891891891895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '1954781', 'n_tokens_mistral': 919, 'n_tokens_neox': 862, 'n_words': 188}