Read about our upcoming Code of Conduct on this issue

milestone.rb 959 Bytes
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1
class Milestone < ActiveRecord::Base
2
3
  attr_accessible :title, :description, :due_date, :closed

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4
5
6
  belongs_to :project
  has_many :issues

Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
7
8
  validates :title, presence: true
  validates :project, presence: true
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
9
10

  def self.active
11
    where("due_date > ? OR due_date IS NULL", Date.today)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
12
13
  end

14
  def participants
Nihad Abbasov's avatar
Nihad Abbasov committed
15
    User.where(id: issues.pluck(:assignee_id))
16
17
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
18
  def percent_complete
19
20
21
    ((self.issues.closed.count * 100) / self.issues.count).abs
  rescue ZeroDivisionError
    100
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
22
23
24
25
26
27
  end

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

# == 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
#