<commit_before>class Authentication < ActiveRecord::Base

  serialize :auth

  belongs_to :user

  validates :provider, :uid, presence: true
  validates :uid, uniqueness: { scope: :provider }
  validates :provider, uniqueness: { scope: :user_id }

  def self.find_or_create_by_hash(auth_hash, user)
    where(auth_hash.slice(:provider, :uid)).first_or_initialize.tap do |auth|
      auth.provider = auth_hash.provider
      auth.uid = auth_hash.uid
      auth.auth = auth_hash
      if auth.user.present?
        user.destroy! if user.guest?
      else
        user.guest = false
        user.name = auth.auth.info["name"]
        user.avatar = auth.auth.info["image"]
        user.save!
        auth.user = user
      end
      auth.save!
    end
  end

end<commit_msg>Dont delete guests<commit_after>class Authentication < ActiveRecord::Base

  serialize :auth

  belongs_to :user

  validates :provider, :uid, presence: true
  validates :uid, uniqueness: { scope: :provider }
  validates :provider, uniqueness: { scope: :user_id }

  def self.find_or_create_by_hash(auth_hash, user)
    where(auth_hash.slice(:provider, :uid)).first_or_initialize.tap do |auth|
      auth.provider = auth_hash.provider
      auth.uid = auth_hash.uid
      auth.auth = auth_hash
      unless auth.user
        user.guest = false
        user.name = auth.auth.info["name"]
        user.avatar = auth.auth.info["image"]
        user.save!
        auth.user = user
      end
      auth.save!
    end
  end

end
{'fraction_non_alphanumeric': 0.10589812332439678, 'fraction_numerical': 0.0, 'mean_word_length': 2.7893401015228427, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2617203', 'n_tokens_mistral': 488, 'n_tokens_neox': 473, 'n_words': 107}