milestone.rb 930 Bytes
Newer Older
1
class Milestone < ActiveRecord::Base
2 3
  attr_accessible :title, :description, :due_date, :closed

4 5 6
  belongs_to :project
  has_many :issues

7
  validates_presence_of :title, :project_id
8 9

  def self.active
10
    where("due_date > ? OR due_date IS NULL", Date.today)
11 12
  end

13
  def participants
14
    User.where(id: issues.map(&:assignee_id))
15 16
  end

17
  def percent_complete
18 19 20
    ((self.issues.closed.count * 100) / self.issues.count).abs
  rescue ZeroDivisionError
    100
21 22 23 24 25 26
  end

  def expires_at
    "expires at #{due_date.stamp("Aug 21, 2011")}" if due_date
  end
end
27 28 29 30 31 32 33 34 35 36 37 38 39 40

# == Schema Information
#
# Table name: milestones
#
#  id          :integer         not null, primary key
#  title       :string(255)     not null
#  project_id  :integer         not null
#  description :text
#  due_date    :date
#  closed      :boolean         default(FALSE), not null
#  created_at  :datetime        not null
#  updated_at  :datetime        not null
#