<commit_before>class PayformItem < ActiveRecord::Base

  belongs_to :payform
  belongs_to :payform_item
  belongs_to :payform_item_set
	belongs_to :category

  delegate :department, :to => :category
  delegate :user, :to => :payform

  # commented out :category_id since it is not fully functional
  # and yet it tries to prevent the creation of new payform_items
  validates_presence_of :description, :date #:category_id
  validates_numericality_of :hours
  
  attr_protected :reason

  named_scope :active, lambda { |*args| { :conditions => ['active = ?',  true] } }
  
  
  
  protected
  
  def validate
    errors.add(:description, "seems too short") if description.length < 10 and description.length > 0
    errors.add(:reason, "seems too short") if description.length < 10 and description.length > 0 && !payform_item.active
    errors.add(:date, "is invalid") if !Date.valid_civil?(date.year, date.month, date.day)
    errors.add(:date, "cannot be in the future") if date > Time.now.to_date
    #TODO: If it's active, it must belong to a payform. If not, it's an edit.
  end

end<commit_msg>fixed validation<commit_after>class PayformItem < ActiveRecord::Base

  belongs_to :payform
  belongs_to :payform_item
  belongs_to :payform_item_set
	belongs_to :category

  delegate :department, :to => :category
  delegate :user, :to => :payform

  # commented out :category_id since it is not fully functional
  # and yet it tries to prevent the creation of new payform_items
  validates_presence_of :description, :date #:category_id
  validates_numericality_of :hours
  
  attr_protected :reason

  named_scope :active, lambda { |*args| { :conditions => ['active = ?',  true] } }
  
  
  
  protected
  
  def validate
    errors.add(:description, "seems too short") if description.length < 10 and description.length > 0
    errors.add(:reason, "seems too short") if reason.length < 10 and reason.length > 0 && !payform_item.active
    errors.add(:date, "is invalid") if !Date.valid_civil?(date.year, date.month, date.day)
    errors.add(:date, "cannot be in the future") if date > Time.now.to_date
    #TODO: If it's active, it must belong to a payform. If not, it's an edit.
  end

end
{'fraction_non_alphanumeric': 0.10232983097304706, 'fraction_numerical': 0.00548195523069895, 'mean_word_length': 4.069444444444445, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '4408907', 'n_tokens_mistral': 722, 'n_tokens_neox': 697, 'n_words': 224}