2019-03-30 07:23:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 07:56:52 +00:00
|
|
|
require 'spec_helper'
|
2016-12-23 05:44:02 +00:00
|
|
|
|
2017-06-29 04:13:10 +00:00
|
|
|
RSpec.describe Timelog do
|
2016-12-23 05:44:02 +00:00
|
|
|
subject { build(:timelog) }
|
2019-10-18 11:11:44 +00:00
|
|
|
|
2017-01-26 01:16:09 +00:00
|
|
|
let(:issue) { create(:issue) }
|
|
|
|
let(:merge_request) { create(:merge_request) }
|
2016-12-23 05:44:02 +00:00
|
|
|
|
2018-06-01 15:09:08 +00:00
|
|
|
it { is_expected.to belong_to(:issue).touch(true) }
|
|
|
|
it { is_expected.to belong_to(:merge_request).touch(true) }
|
|
|
|
|
2016-12-23 05:44:02 +00: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-26 01:16:09 +00: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
|
2020-12-16 15:10:18 +00:00
|
|
|
|
|
|
|
describe 'when importing' do
|
|
|
|
it 'is valid if issue_id and merge_request_id are missing' do
|
|
|
|
subject.attributes = { issue: nil, merge_request: nil, importing: true }
|
|
|
|
|
|
|
|
expect(subject).to be_valid
|
|
|
|
end
|
|
|
|
end
|
2017-01-26 01:16:09 +00:00
|
|
|
end
|
2019-12-10 12:07:55 +00:00
|
|
|
|
|
|
|
describe 'scopes' do
|
|
|
|
describe 'for_issues_in_group' do
|
|
|
|
it 'return timelogs created for group issues' do
|
|
|
|
group = create(:group)
|
|
|
|
subgroup = create(:group, parent: group)
|
|
|
|
|
|
|
|
create(:timelog, issue: create(:issue, project: create(:project)))
|
|
|
|
timelog1 = create(:timelog, issue: create(:issue, project: create(:project, group: group)))
|
|
|
|
timelog2 = create(:timelog, issue: create(:issue, project: create(:project, group: subgroup)))
|
|
|
|
|
|
|
|
expect(described_class.for_issues_in_group(group)).to contain_exactly(timelog1, timelog2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-05 12:09:31 +00:00
|
|
|
describe 'between_times' do
|
|
|
|
it 'returns collection of timelogs within given times' do
|
2019-12-10 12:07:55 +00:00
|
|
|
create(:timelog, spent_at: 65.days.ago)
|
|
|
|
timelog1 = create(:timelog, spent_at: 15.days.ago)
|
|
|
|
timelog2 = create(:timelog, spent_at: 5.days.ago)
|
2020-05-05 12:09:31 +00:00
|
|
|
timelogs = described_class.between_times(20.days.ago, 1.day.ago)
|
2019-12-10 12:07:55 +00:00
|
|
|
|
|
|
|
expect(timelogs).to contain_exactly(timelog1, timelog2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-12-23 05:44:02 +00:00
|
|
|
end
|