2015-11-26 14:37:03 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe GlobalMilestone do
|
2015-11-26 14:37:03 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let(:group) { create(:group) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project1) { create(:project, group: group) }
|
|
|
|
let(:project2) { create(:project, path: 'gitlab-ci', group: group) }
|
|
|
|
let(:project3) { create(:project, path: 'cookbook-gitlab', group: group) }
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '.build_collection' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:milestone1_due_date) { 2.weeks.from_now.to_date }
|
|
|
|
|
|
|
|
let!(:milestone1_project1) do
|
|
|
|
create(
|
|
|
|
:milestone,
|
|
|
|
title: "Milestone v1.2",
|
|
|
|
project: project1,
|
|
|
|
due_date: milestone1_due_date
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:milestone1_project2) do
|
|
|
|
create(
|
|
|
|
:milestone,
|
|
|
|
title: "Milestone v1.2",
|
|
|
|
project: project2,
|
|
|
|
due_date: milestone1_due_date
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:milestone1_project3) do
|
|
|
|
create(
|
|
|
|
:milestone,
|
|
|
|
title: "Milestone v1.2",
|
|
|
|
project: project3,
|
|
|
|
due_date: milestone1_due_date
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:milestone2_project1) do
|
|
|
|
create(
|
|
|
|
:milestone,
|
|
|
|
title: "VD-123",
|
|
|
|
project: project1,
|
|
|
|
due_date: nil
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:milestone2_project2) do
|
|
|
|
create(
|
|
|
|
:milestone,
|
|
|
|
title: "VD-123",
|
|
|
|
project: project2,
|
|
|
|
due_date: nil
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:milestone2_project3) do
|
|
|
|
create(
|
|
|
|
:milestone,
|
|
|
|
title: "VD-123",
|
|
|
|
project: project3,
|
|
|
|
due_date: nil
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
before do
|
2017-08-17 22:00:37 +05:30
|
|
|
projects = [
|
|
|
|
project1,
|
|
|
|
project2,
|
|
|
|
project3
|
|
|
|
]
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
@global_milestones = described_class.build_collection(projects, {})
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'has all project milestones' do
|
2015-11-26 14:37:03 +05:30
|
|
|
expect(@global_milestones.count).to eq(2)
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'has all project milestones titles' do
|
2015-11-26 14:37:03 +05:30
|
|
|
expect(@global_milestones.map(&:title)).to match_array(['Milestone v1.2', 'VD-123'])
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'has all project milestones' do
|
2015-11-26 14:37:03 +05:30
|
|
|
expect(@global_milestones.map { |group_milestone| group_milestone.milestones.count }.sum).to eq(6)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
it 'sorts collection by due date' do
|
|
|
|
expect(@global_milestones.map(&:due_date)).to eq [nil, milestone1_due_date]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.states_count' do
|
|
|
|
context 'when the projects have milestones' do
|
|
|
|
before do
|
|
|
|
create(:closed_milestone, title: 'Active Group Milestone', project: project3)
|
|
|
|
create(:active_milestone, title: 'Active Group Milestone', project: project1)
|
|
|
|
create(:active_milestone, title: 'Active Group Milestone', project: project2)
|
|
|
|
create(:closed_milestone, title: 'Closed Group Milestone', project: project1)
|
|
|
|
create(:closed_milestone, title: 'Closed Group Milestone', project: project2)
|
|
|
|
create(:closed_milestone, title: 'Closed Group Milestone', project: project3)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the quantity of global milestones in each possible state' do
|
|
|
|
expected_count = { opened: 1, closed: 2, all: 2 }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
count = described_class.states_count(Project.all)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(count).to eq(expected_count)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the projects do not have milestones' do
|
|
|
|
before do
|
|
|
|
project1
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 0 as the quantity of global milestones in each state' do
|
|
|
|
expected_count = { opened: 0, closed: 0, all: 0 }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
count = described_class.states_count(Project.all)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(count).to eq(expected_count)
|
|
|
|
end
|
|
|
|
end
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#initialize' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:milestone1_project1) { create(:milestone, title: "Milestone v1.2", project: project1) }
|
|
|
|
let(:milestone1_project2) { create(:milestone, title: "Milestone v1.2", project: project2) }
|
|
|
|
let(:milestone1_project3) { create(:milestone, title: "Milestone v1.2", project: project3) }
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
before do
|
|
|
|
milestones =
|
|
|
|
[
|
|
|
|
milestone1_project1,
|
|
|
|
milestone1_project2,
|
2017-09-10 17:25:29 +05:30
|
|
|
milestone1_project3
|
2015-11-26 14:37:03 +05:30
|
|
|
]
|
2016-11-03 12:29:30 +05:30
|
|
|
milestones_relation = Milestone.where(id: milestones.map(&:id))
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
@global_milestone = described_class.new(milestone1_project1.title, milestones_relation)
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'has exactly one group milestone' do
|
2015-11-26 14:37:03 +05:30
|
|
|
expect(@global_milestone.title).to eq('Milestone v1.2')
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'has all project milestones with the same title' do
|
2015-11-26 14:37:03 +05:30
|
|
|
expect(@global_milestone.milestones.count).to eq(3)
|
|
|
|
end
|
|
|
|
end
|
2016-01-14 18:37:52 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#safe_title' do
|
2016-01-14 18:37:52 +05:30
|
|
|
let(:milestone) { create(:milestone, title: "git / test", project: project1) }
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'strips out slashes and spaces' do
|
2017-09-10 17:25:29 +05:30
|
|
|
global_milestone = described_class.new(milestone.title, Milestone.where(id: milestone.id))
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
expect(global_milestone.safe_title).to eq('git-test')
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '#state' do
|
|
|
|
context 'when at least one milestone is active' do
|
|
|
|
it 'returns active' do
|
|
|
|
title = 'Active Group Milestone'
|
|
|
|
milestones = [
|
|
|
|
create(:active_milestone, title: title),
|
|
|
|
create(:closed_milestone, title: title)
|
|
|
|
]
|
2017-09-10 17:25:29 +05:30
|
|
|
global_milestone = described_class.new(title, milestones)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(global_milestone.state).to eq('active')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when all milestones are closed' do
|
|
|
|
it 'returns closed' do
|
|
|
|
title = 'Closed Group Milestone'
|
|
|
|
milestones = [
|
|
|
|
create(:closed_milestone, title: title),
|
|
|
|
create(:closed_milestone, title: title)
|
|
|
|
]
|
2017-09-10 17:25:29 +05:30
|
|
|
global_milestone = described_class.new(title, milestones)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(global_milestone.state).to eq('closed')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|