Milestone uses StateMachine now

This commit is contained in:
Andrew8xx8 2013-02-18 13:10:09 +04:00
parent 29f70acc98
commit 0b512af803
7 changed files with 39 additions and 25 deletions

View file

@ -13,19 +13,32 @@
#
class Milestone < ActiveRecord::Base
attr_accessible :title, :description, :due_date, :closed, :author_id_of_changes
attr_accessible :title, :description, :due_date, :state_event, :author_id_of_changes
attr_accessor :author_id_of_changes
belongs_to :project
has_many :issues
has_many :merge_requests
scope :active, -> { where(closed: false) }
scope :closed, -> { where(closed: true) }
scope :active, -> { with_state(:active) }
scope :closed, -> { with_state(:closed) }
validates :title, presence: true
validates :project, presence: true
validates :closed, inclusion: { in: [true, false] }
state_machine :state, :initial => :active do
event :close do
transition :active => :closed
end
event :activate do
transition :closed => :active
end
state :closed
state :active
end
def expired?
if due_date
@ -68,17 +81,13 @@ class Milestone < ActiveRecord::Base
end
def can_be_closed?
open? && issues.opened.count.zero?
active? && issues.opened.count.zero?
end
def is_empty?
total_items_count.zero?
end
def open?
!closed
end
def author_id
author_id_of_changes
end