summaryrefslogtreecommitdiff
path: root/app/models/timelog.rb
blob: e166cf69703a960e711b4dd908f2d1f3e110bdef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Timelog < ActiveRecord::Base
  validates :time_spent, :user, presence: true
  validate :issuable_id_is_present

  belongs_to :issue
  belongs_to :merge_request
  belongs_to :user

  def issuable
    issue || merge_request
  end

  private

  def issuable_id_is_present
    if issue_id && merge_request_id
      errors.add(:base, 'Only Issue ID or Merge Request ID is required')
    elsif issuable.nil?
      errors.add(:base, 'Issue or Merge Request ID is required')
    end
  end
end