<commit_before>class GroupRequest < ActiveRecord::Base

  attr_accessible :name, :description, :expected_size, :admin_name, :admin_email,
                  :cannot_contribute, :max_size, :high_touch, :robot_trap

  attr_accessor :robot_trap

  validates :name, presence: true, length: {maximum: 250}
  validates :description, presence: true
  validates :expected_size, presence: true
  validates :admin_name, presence: true, length: {maximum: 250}
  validates :admin_email, presence: true, email: true
  validates_inclusion_of :cannot_contribute, :in => [true, false], message: I18n.t("error.group_request_contribution")

  belongs_to :group
  belongs_to :approved_by, class_name: 'User'

  scope :verified, where(:status => :verified)
  scope :unverified, where(:status => :unverified)
  scope :approved, where(:status => :approved)
  scope :accepted, where(:status => :accepted)

  before_destroy :prevent_destroy_if_group_present
  before_create :mark_spam
  before_validation :generate_token, on: :create

  include AASM
  aasm column: :status do  # defaults to aasm_state
    state :unverified, initial: true
    state :verified
    state :approved
    state :accepted
    state :defered
    state :manually_approved
    state :marked_as_spam

    event :verify do
      transitions to: :verified, from: [:unverified, :defered]
    end

    event :approve_request do
      transitions to: :approved, from: [:verified, :defered]
    end

    event :accept_request do
      transitions to: :accepted, from: [:approved]
    end

    event :defer do
      transitions to: :defered, from: [:verified]
    end

    event :mark_as_manually_approved do
      transitions to: :manually_approved, from: [:unverified, :verified, :defered]
    end

    event :mark_as_spam do
      transitions to: :marked_as_spam, from: [:unverified, :verified, :defered]
    end

    event :mark_as_unverified do
      transitions to: :unverified, from: [:marked_as_spam, :manually_approved]
    end

  end

  def approve!(args)
    self.approved_by = args[:approved_by]
    update_attribute(:approved_at, DateTime.now)
    approve_request!
  end
<commit_msg>Add extra cautious save to GroupRequest#approve!<commit_after>class GroupRequest < ActiveRecord::Base

  attr_accessible :name, :description, :expected_size, :admin_name, :admin_email,
                  :cannot_contribute, :max_size, :high_touch, :robot_trap

  attr_accessor :robot_trap

  validates :name, presence: true, length: {maximum: 250}
  validates :description, presence: true
  validates :expected_size, presence: true
  validates :admin_name, presence: true, length: {maximum: 250}
  validates :admin_email, presence: true, email: true
  validates_inclusion_of :cannot_contribute, :in => [true, false], message: I18n.t("error.group_request_contribution")

  belongs_to :group
  belongs_to :approved_by, class_name: 'User'

  scope :verified, where(:status => :verified)
  scope :unverified, where(:status => :unverified)
  scope :approved, where(:status => :approved)
  scope :accepted, where(:status => :accepted)

  before_destroy :prevent_destroy_if_group_present
  before_create :mark_spam
  before_validation :generate_token, on: :create

  include AASM
  aasm column: :status do  # defaults to aasm_state
    state :unverified, initial: true
    state :verified
    state :approved
    state :accepted
    state :defered
    state :manually_approved
    state :marked_as_spam

    event :verify do
      transitions to: :verified, from: [:unverified, :defered]
    end

    event :approve_request do
      transitions to: :approved, from: [:verified, :defered]
    end

    event :accept_request do
      transitions to: :accepted, from: [:approved]
    end

    event :defer do
      transitions to: :defered, from: [:verified]
    end

    event :mark_as_manually_approved do
      transitions to: :manually_approved, from: [:unverified, :verified, :defered]
    end

    event :mark_as_spam do
      transitions to: :marked_as_spam, from: [:unverified, :verified, :defered]
    end

    event :mark_as_unverified do
      transitions to: :unverified, from: [:marked_as_spam, :manually_approved]
    end

  end

  def approve!(args)
    self.approved_by = args[:approved_by]
    update_attribute(:approved_at, DateTime.now)
    approve_request!
    save!
  end

{'fraction_non_alphanumeric': 0.09655012734429266, 'fraction_numerical': 0.0037045612410280156, 'mean_word_length': 4.161290322580645, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '7120179', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1392, 'n_words': 374}