2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-05-18 00:54:41 +05:30
|
|
|
class Timelog < ApplicationRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
validates :time_spent, :user, presence: true
|
|
|
|
validate :issuable_id_is_present
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
belongs_to :issue, touch: true
|
|
|
|
belongs_to :merge_request, touch: true
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
# Rails5 defaults to :touch_later, overwrite for normal touch
|
|
|
|
def belongs_to_touch_method
|
|
|
|
:touch
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|