<commit_before>module Actions
  class RedeemBadgeClaim
    include Actions::Transactional
    attr_reader :badge_claim, :user

    def initialize(badge_claim, user)
      @badge_claim = badge_claim
      @user = user
    end

    private
    def execute
      if @badge_claim.user.nil?
        if @user.badges.include?(@badge_claim.badge)
          errors << "#{@user.display_name} already has badge #{@badge_claim.badge.name}"
        end
        @user.badges.push(@badge_claim.badge)
        @user.save
        @badge_claim.save
      elsif @badge_claim.user == @user
        errors << "#{@user.display_name} has already used this badge claim"
      else
        errors << "badge already claimed by #{@badge_claim.user.display_name}"
      end
    end
  end
end<commit_msg>fix multiple badge bug<commit_after>module Actions
  class RedeemBadgeClaim
    include Actions::Transactional
    attr_reader :badge_claim, :user

    def initialize(badge_claim, user)
      @badge_claim = badge_claim
      @user = user
    end

    private
    def execute
      if @badge_claim.user.nil?
        if @user.badges.include?(@badge_claim.badge)
          errors << "#{@user.display_name} already has badge #{@badge_claim.badge.name}"
          return
        end
        @user.badges.push(@badge_claim.badge)
        @user.save
        @badge_claim.user = @user
        @badge_claim.save
      elsif @badge_claim.user == @user
        errors << "#{@user.display_name} has already used this badge claim"
      else
        errors << "badge already claimed by #{@badge_claim.user.display_name}"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09813664596273292, 'fraction_numerical': 0.0, 'mean_word_length': 2.5406593406593405, 'pattern_counts': {'":': 0, '<': 15, '<?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': '3856261', 'n_tokens_mistral': 526, 'n_tokens_neox': 510, 'n_words': 117}