2016-12-23 00:44:02 -05:00
|
|
|
class Timelog < ActiveRecord::Base
|
|
|
|
validates :time_spent, :user, presence: true
|
2017-01-25 20:16:09 -05:00
|
|
|
validate :issuable_id_is_present
|
2016-12-23 00:44:02 -05:00
|
|
|
|
2017-01-25 20:16:09 -05:00
|
|
|
belongs_to :issue
|
|
|
|
belongs_to :merge_request
|
2016-12-23 00:44:02 -05:00
|
|
|
belongs_to :user
|
2017-01-25 20:16:09 -05:00
|
|
|
|
|
|
|
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
|
2016-12-23 00:44:02 -05:00
|
|
|
end
|