<commit_before>class User < ApplicationRecord
  include PgSearch
  include AuthenticatingUser
  include RivalUser
  include RunnerUser

  has_many :runs
  has_many :categories, -> { distinct }, through: :runs
  has_many :games,      -> { distinct }, through: :runs

  has_many :rivalries,          foreign_key: :from_user_id, dependent: :destroy
  has_many :incoming_rivalries, foreign_key: :to_user_id,   dependent: :destroy, class_name: 'Rivalry'

  has_many :twitch_user_follows,   foreign_key: :from_user_id, dependent: :destroy
  has_many :twitch_user_followers, foreign_key: :to_user_id,   dependent: :destroy, class_name: 'TwitchUserFollow'

  has_many :twitch_follows,   class_name: 'User', through: :twitch_user_follows
  has_many :twitch_followers, class_name: 'User', through: :twitch_user_followers

  has_one  :patreon, class_name: 'PatreonUser', dependent: :destroy
  has_one  :twitch,  class_name: 'TwitchUser',  dependent: :destroy

  has_many :applications,  class_name: 'Doorkeeper::Application', foreign_key: :owner_id
  has_many :access_grants, class_name: 'Doorkeeper::AccessGrant', foreign_key: :resource_owner_id
  has_many :access_tokens, class_name: 'Doorkeeper::AccessToken', foreign_key: :resource_owner_id

  after_destroy do |user|
    user.runs.update_all(user_id: nil)
  end

  validates :name, presence: true

  scope :with_runs, -> { joins(:runs).distinct }
  scope :that_run, ->(category) { joins(:runs).where(runs: {category: category}).distinct }
  pg_search_scope :search_for_name, against: :name, using: :trigram

  def self.search(term)
    term = term.strip
    return nil if term.blank?
    search_for_name(term)
  end
<commit_msg>Fix tests really<commit_after>class User < ApplicationRecord
  include PgSearch
  include AuthenticatingUser
  include RivalUser
  include RunnerUser

  has_many :runs
  has_many :categories, -> { distinct }, through: :runs
  has_many :games,      -> { distinct }, through: :runs

  has_many :rivalries,          foreign_key: :from_user_id, dependent: :destroy
  has_many :incoming_rivalries, foreign_key: :to_user_id,   dependent: :destroy, class_name: 'Rivalry'

  has_many :twitch_user_follows,   foreign_key: :from_user_id, dependent: :destroy
  has_many :twitch_user_followers, foreign_key: :to_user_id,   dependent: :destroy, class_name: 'TwitchUserFollow'

  has_many :twitch_follows,   class_name: 'User', through: :twitch_user_follows,   source: :to_user
  has_many :twitch_followers, class_name: 'User', through: :twitch_user_followers, source: :from_user

  has_one  :patreon, class_name: 'PatreonUser', dependent: :destroy
  has_one  :twitch,  class_name: 'TwitchUser',  dependent: :destroy

  has_many :applications,  class_name: 'Doorkeeper::Application', foreign_key: :owner_id
  has_many :access_grants, class_name: 'Doorkeeper::AccessGrant', foreign_key: :resource_owner_id
  has_many :access_tokens, class_name: 'Doorkeeper::AccessToken', foreign_key: :resource_owner_id

  after_destroy do |user|
    user.runs.update_all(user_id: nil)
  end

  validates :name, presence: true

  scope :with_runs, -> { joins(:runs).distinct }
  scope :that_run, ->(category) { joins(:runs).where(runs: {category: category}).distinct }
  pg_search_scope :search_for_name, against: :name, using: :trigram

  def self.search(term)
    term = term.strip
    return nil if term.blank?
    search_for_name(term)
  end

{'fraction_non_alphanumeric': 0.10569825804546797, 'fraction_numerical': 0.0, 'mean_word_length': 5.453333333333333, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7013214', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1153, 'n_words': 262}