<commit_before>class Task < RoleRecord
  include Immortal
  
  include Watchable

  STATUS_NAMES = [:new, :open, :hold, :resolved, :rejected]

  # values equal or bigger than :resolved will be considered as archived tasks
  STATUSES = STATUS_NAMES.each_with_index.each_with_object({}) {|(name, code), all| all[name] = code }

  ACTIVE_STATUS_CODES = [:new, :open].map { |name| STATUSES[name] }

  concerned_with :scopes, :callbacks
  
  has_one  :first_comment, :class_name => 'Comment', :as => :target, :order => 'created_at ASC'
  has_many :recent_comments, :class_name => 'Comment', :as => :target, :order => 'created_at DESC', :limit => 2

  belongs_to :task_list, :counter_cache => true
  belongs_to :page

  # RAILS3 fix with_deleted
  belongs_to :assigned, :class_name => 'Person'#, :with_deleted => true
  has_many :comments, :as => :target, :order => 'created_at DESC', :dependent => :destroy

  accepts_nested_attributes_for :comments, :allow_destroy => false,
    :reject_if => lambda { |comment| %w[body hours human_hours uploads_attributes].all? { |k| comment[k].blank? } }

  attr_accessible :name, :assigned_id, :status, :due_on, :comments_attributes

  validates_presence_of :name, :message => I18n.t('tasks.errors.name.cant_be_blank')
  validates_length_of   :name, :maximum => 255, :message => I18n.t('tasks.errors.name.too_long')
  validates_inclusion_of :status, :in => STATUSES.values, :message => "is not a valid status"
  
  validate :check_asignee_membership, :if => :assigned_id?
  
  # set by controller to indicate user that's doing task updating
  attr_accessor :updating_user
  attr_accessor :updating_date

  after_save :update_tasks_counts
  before_validation :copy_project_from_task_list, :if => lambda { |t| t.task_list_id? and not t.project_id? }
  before_save :set_comments_author, :if => :updating_user
  before_save :transition_from_new_to_open, :if => :assigned_id?
  before_save :save_changes_to_comment, :if => :track_changes?<commit_msg>We already fixed this RAILS3<commit_after>class Task < RoleRecord
  include Immortal
  
  include Watchable

  STATUS_NAMES = [:new, :open, :hold, :resolved, :rejected]

  # values equal or bigger than :resolved will be considered as archived tasks
  STATUSES = STATUS_NAMES.each_with_index.each_with_object({}) {|(name, code), all| all[name] = code }

  ACTIVE_STATUS_CODES = [:new, :open].map { |name| STATUSES[name] }

  concerned_with :scopes, :callbacks
  
  has_one  :first_comment, :class_name => 'Comment', :as => :target, :order => 'created_at ASC'
  has_many :recent_comments, :class_name => 'Comment', :as => :target, :order => 'created_at DESC', :limit => 2

  belongs_to :task_list, :counter_cache => true
  belongs_to :page

  belongs_to :assigned, :class_name => 'Person'
  has_many :comments, :as => :target, :order => 'created_at DESC', :dependent => :destroy

  accepts_nested_attributes_for :comments, :allow_destroy => false,
    :reject_if => lambda { |comment| %w[body hours human_hours uploads_attributes].all? { |k| comment[k].blank? } }

  attr_accessible :name, :assigned_id, :status, :due_on, :comments_attributes

  validates_presence_of :name, :message => I18n.t('tasks.errors.name.cant_be_blank')
  validates_length_of   :name, :maximum => 255, :message => I18n.t('tasks.errors.name.too_long')
  validates_inclusion_of :status, :in => STATUSES.values, :message => "is not a valid status"
  
  validate :check_asignee_membership, :if => :assigned_id?
  
  # set by controller to indicate user that's doing task updating
  attr_accessor :updating_user
  attr_accessor :updating_date

  after_save :update_tasks_counts
  before_validation :copy_project_from_task_list, :if => lambda { |t| t.task_list_id? and not t.project_id? }
  before_save :set_comments_author, :if => :updating_user
  before_save :transition_from_new_to_open, :if => :assigned_id?
  before_save :save_changes_to_comment, :if => :track_changes?
{'fraction_non_alphanumeric': 0.12605256442970145, 'fraction_numerical': 0.0045930084205154376, 'mean_word_length': 5.447368421052632, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, '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': '4356881', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1353, 'n_words': 326}