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 )
13 enum type: %w( administrator moderator )
15 scope :with_status, -> (issue_status) { where(:status => statuses[issue_status])}
18 resolved_at.present? ? reports.where("updated_at < ?", resolved_at) : nil
22 resolved_at.present? ? reports.where("updated_at >= ?", resolved_at) : reports
26 aasm :column => :status, :no_direct_assignment => true do
27 state :open, :initial => true
32 transitions :from => :open, :to => :ignored
36 transitions :from => :open, :to => :resolved
38 self.resolved_at = Time.now.getutc
43 transitions :from => :resolved, :to => :open
44 transitions :from => :ignored, :to => :open