diff options
author | Andrew8xx8 <avk@8xx8.ru> | 2013-02-18 13:10:09 +0400 |
---|---|---|
committer | Andrew8xx8 <avk@8xx8.ru> | 2013-02-18 14:43:50 +0400 |
commit | 0b512af803d007852bcba40c75203e0e45dda177 (patch) | |
tree | d85179b7bf98fb9de7cd7c6d7d7557dfe8db0939 /app/models | |
parent | 29f70acc987abe0b188ef187c70f179088d79589 (diff) |
Milestone uses StateMachine now
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/milestone.rb | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 457fe18f35b..23b414467ca 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -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 |