1 class Issue < ActiveRecord::Base
2 belongs_to :reportable, :polymorphic => true
4 validates :reportable_id, :uniqueness => { :scope => [ :reportable_type ] }
7 # Check if more statuses are needed
8 enum status: %w( open ignored resolved )
10 scope :with_status, -> (issue_status) { where(:status => statuses[issue_status])}
13 resolved_at.present? ? reports.where("created_at < ?", resolved_at) : nil
17 resolved_at.present? ? reports.where("created_at >= ?", resolved_at) : reports
21 aasm :column => :status, :no_direct_assignment => true do
22 state :open, :initial => true
27 transitions :from => :open, :to => :ignored
31 transitions :from => :open, :to => :resolved
33 self.resolved_at = Time.now.getutc
38 transitions :from => :resolved, :to => :open