1 class Issue < ActiveRecord::Base
2 belongs_to :reportable, :polymorphic => true
3 belongs_to :user, :class_name => "User", :foreign_key => :reported_user_id
6 has_many :comments, :class_name => "IssueComment"
8 validates :reportable_id, :uniqueness => { :scope => [ :reportable_type ] }
9 validates :reported_user_id, :presence => true
11 # Check if more statuses are needed
12 enum status: %w( open ignored resolved )
14 scope :with_status, -> (issue_status) { where(:status => statuses[issue_status])}
17 resolved_at.present? ? reports.where("created_at < ?", resolved_at) : nil
21 resolved_at.present? ? reports.where("created_at >= ?", resolved_at) : reports
25 aasm :column => :status, :no_direct_assignment => true do
26 state :open, :initial => true
31 transitions :from => :open, :to => :ignored
35 transitions :from => :open, :to => :resolved
37 self.resolved_at = Time.now.getutc
42 transitions :from => :resolved, :to => :open