2016-03-17 16:59:30 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Milestone, 'Milestoneish' do
|
|
|
|
let(:author) { create(:user) }
|
|
|
|
let(:assignee) { create(:user) }
|
|
|
|
let(:non_member) { create(:user) }
|
|
|
|
let(:member) { create(:user) }
|
2016-06-06 15:13:31 -04:00
|
|
|
let(:guest) { create(:user) }
|
2016-03-17 16:59:30 -04:00
|
|
|
let(:admin) { create(:admin) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :public) }
|
2016-03-17 16:59:30 -04:00
|
|
|
let(:milestone) { create(:milestone, project: project) }
|
|
|
|
let!(:issue) { create(:issue, project: project, milestone: milestone) }
|
|
|
|
let!(:security_issue_1) { create(:issue, :confidential, project: project, author: author, milestone: milestone) }
|
2017-05-04 08:11:15 -04:00
|
|
|
let!(:security_issue_2) { create(:issue, :confidential, project: project, assignees: [assignee], milestone: milestone) }
|
2016-03-17 16:59:30 -04:00
|
|
|
let!(:closed_issue_1) { create(:issue, :closed, project: project, milestone: milestone) }
|
|
|
|
let!(:closed_issue_2) { create(:issue, :closed, project: project, milestone: milestone) }
|
|
|
|
let!(:closed_security_issue_1) { create(:issue, :confidential, :closed, project: project, author: author, milestone: milestone) }
|
2017-05-04 08:11:15 -04:00
|
|
|
let!(:closed_security_issue_2) { create(:issue, :confidential, :closed, project: project, assignees: [assignee], milestone: milestone) }
|
2016-03-17 16:59:30 -04:00
|
|
|
let!(:closed_security_issue_3) { create(:issue, :confidential, :closed, project: project, author: author, milestone: milestone) }
|
2017-05-04 08:11:15 -04:00
|
|
|
let!(:closed_security_issue_4) { create(:issue, :confidential, :closed, project: project, assignees: [assignee], milestone: milestone) }
|
2016-03-17 16:59:30 -04:00
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: milestone) }
|
2017-06-09 11:54:20 -04:00
|
|
|
let(:label_1) { create(:label, title: 'label_1', project: project, priority: 1) }
|
|
|
|
let(:label_2) { create(:label, title: 'label_2', project: project, priority: 2) }
|
|
|
|
let(:label_3) { create(:label, title: 'label_3', project: project) }
|
2016-03-17 16:59:30 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.team << [member, :developer]
|
2016-06-06 15:13:31 -04:00
|
|
|
project.team << [guest, :guest]
|
2016-03-17 16:59:30 -04:00
|
|
|
end
|
|
|
|
|
2017-06-09 14:53:32 -04:00
|
|
|
describe '#sorted_issues' do
|
2017-06-09 11:54:20 -04:00
|
|
|
it 'sorts issues by label priority' do
|
|
|
|
issue.labels << label_1
|
|
|
|
security_issue_1.labels << label_2
|
|
|
|
closed_issue_1.labels << label_3
|
|
|
|
|
2017-06-09 14:53:32 -04:00
|
|
|
issues = milestone.sorted_issues(member)
|
2017-06-09 11:54:20 -04:00
|
|
|
|
|
|
|
expect(issues.first).to eq(issue)
|
|
|
|
expect(issues.second).to eq(security_issue_1)
|
|
|
|
expect(issues.third).not_to eq(closed_issue_1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#sorted_merge_requests' do
|
|
|
|
it 'sorts merge requests by label priority' do
|
2017-06-09 14:53:32 -04:00
|
|
|
merge_request_1 = create(:labeled_merge_request, labels: [label_2], source_project: project, source_branch: 'branch_1', milestone: milestone)
|
|
|
|
merge_request_2 = create(:labeled_merge_request, labels: [label_1], source_project: project, source_branch: 'branch_2', milestone: milestone)
|
|
|
|
merge_request_3 = create(:labeled_merge_request, labels: [label_3], source_project: project, source_branch: 'branch_3', milestone: milestone)
|
2017-06-09 11:54:20 -04:00
|
|
|
|
|
|
|
merge_requests = milestone.sorted_merge_requests
|
|
|
|
|
|
|
|
expect(merge_requests.first).to eq(merge_request_2)
|
|
|
|
expect(merge_requests.second).to eq(merge_request_1)
|
|
|
|
expect(merge_requests.third).to eq(merge_request_3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-17 16:59:30 -04:00
|
|
|
describe '#closed_items_count' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not count confidential issues for non project members' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.closed_items_count(non_member)).to eq 2
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not count confidential issues for project members with guest role' do
|
2016-06-06 15:13:31 -04:00
|
|
|
expect(milestone.closed_items_count(guest)).to eq 2
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'counts confidential issues for author' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.closed_items_count(author)).to eq 4
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'counts confidential issues for assignee' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.closed_items_count(assignee)).to eq 4
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'counts confidential issues for project members' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.closed_items_count(member)).to eq 6
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'counts all issues for admin' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.closed_items_count(admin)).to eq 6
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#total_items_count' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not count confidential issues for non project members' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.total_items_count(non_member)).to eq 4
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not count confidential issues for project members with guest role' do
|
2016-06-06 15:13:31 -04:00
|
|
|
expect(milestone.total_items_count(guest)).to eq 4
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'counts confidential issues for author' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.total_items_count(author)).to eq 7
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'counts confidential issues for assignee' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.total_items_count(assignee)).to eq 7
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'counts confidential issues for project members' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.total_items_count(member)).to eq 10
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'counts all issues for admin' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.total_items_count(admin)).to eq 10
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#complete?' do
|
|
|
|
it 'returns false when has items opened' do
|
|
|
|
expect(milestone.complete?(non_member)).to eq false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when all items are closed' do
|
|
|
|
issue.close
|
|
|
|
merge_request.close
|
|
|
|
|
|
|
|
expect(milestone.complete?(non_member)).to eq true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#percent_complete' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not count confidential issues for non project members' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.percent_complete(non_member)).to eq 50
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not count confidential issues for project members with guest role' do
|
2016-06-06 15:13:31 -04:00
|
|
|
expect(milestone.percent_complete(guest)).to eq 50
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'counts confidential issues for author' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.percent_complete(author)).to eq 57
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'counts confidential issues for assignee' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.percent_complete(assignee)).to eq 57
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'counts confidential issues for project members' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.percent_complete(member)).to eq 60
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'counts confidential issues for admin' do
|
2016-03-17 16:59:30 -04:00
|
|
|
expect(milestone.percent_complete(admin)).to eq 60
|
|
|
|
end
|
|
|
|
end
|
2016-11-15 12:48:30 -05:00
|
|
|
|
2017-03-16 07:34:46 -04:00
|
|
|
describe '#remaining_days' do
|
|
|
|
it 'shows 0 if no due date' do
|
|
|
|
milestone = build_stubbed(:milestone)
|
|
|
|
|
|
|
|
expect(milestone.remaining_days).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows 0 if expired' do
|
|
|
|
milestone = build_stubbed(:milestone, due_date: 2.days.ago)
|
|
|
|
|
|
|
|
expect(milestone.remaining_days).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows correct remaining days' do
|
|
|
|
milestone = build_stubbed(:milestone, due_date: 2.days.from_now)
|
|
|
|
|
|
|
|
expect(milestone.remaining_days).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-15 12:48:30 -05:00
|
|
|
describe '#elapsed_days' do
|
|
|
|
it 'shows 0 if no start_date set' do
|
2017-03-16 07:34:46 -04:00
|
|
|
milestone = build_stubbed(:milestone)
|
2016-11-15 12:48:30 -05:00
|
|
|
|
|
|
|
expect(milestone.elapsed_days).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows 0 if start_date is a future' do
|
2017-03-16 07:34:46 -04:00
|
|
|
milestone = build_stubbed(:milestone, start_date: Time.now + 2.days)
|
2016-11-15 12:48:30 -05:00
|
|
|
|
|
|
|
expect(milestone.elapsed_days).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows correct amount of days' do
|
2017-03-16 07:34:46 -04:00
|
|
|
milestone = build_stubbed(:milestone, start_date: Time.now - 2.days)
|
2016-11-15 12:48:30 -05:00
|
|
|
|
|
|
|
expect(milestone.elapsed_days).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
2016-03-17 16:59:30 -04:00
|
|
|
end
|