2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2016-12-23 00:44:02 -05:00
|
|
|
|
2017-06-29 00:13:10 -04:00
|
|
|
RSpec.describe Timelog do
|
2016-12-23 00:44:02 -05:00
|
|
|
subject { build(:timelog) }
|
2017-01-25 20:16:09 -05:00
|
|
|
let(:issue) { create(:issue) }
|
|
|
|
let(:merge_request) { create(:merge_request) }
|
2016-12-23 00:44:02 -05:00
|
|
|
|
2018-06-01 11:09:08 -04:00
|
|
|
it { is_expected.to belong_to(:issue).touch(true) }
|
|
|
|
it { is_expected.to belong_to(:merge_request).touch(true) }
|
|
|
|
|
2016-12-23 00:44:02 -05:00
|
|
|
it { is_expected.to be_valid }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:time_spent) }
|
|
|
|
it { is_expected.to validate_presence_of(:user) }
|
2017-01-25 20:16:09 -05:00
|
|
|
|
|
|
|
describe 'Issuable validation' do
|
|
|
|
it 'is invalid if issue_id and merge_request_id are missing' do
|
|
|
|
subject.attributes = { issue: nil, merge_request: nil }
|
|
|
|
|
|
|
|
expect(subject).to be_invalid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is invalid if issue_id and merge_request_id are set' do
|
|
|
|
subject.attributes = { issue: issue, merge_request: merge_request }
|
|
|
|
|
|
|
|
expect(subject).to be_invalid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is valid if only issue_id is set' do
|
|
|
|
subject.attributes = { issue: issue, merge_request: nil }
|
|
|
|
|
|
|
|
expect(subject).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is valid if only merge_request_id is set' do
|
|
|
|
subject.attributes = { merge_request: merge_request, issue: nil }
|
|
|
|
|
|
|
|
expect(subject).to be_valid
|
|
|
|
end
|
|
|
|
end
|
2016-12-23 00:44:02 -05:00
|
|
|
end
|