2015-11-16 08:38:34 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 04:50:51 -05:00
|
|
|
describe GlobalMilestone, models: true do
|
2015-11-16 08:38:34 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let(:group) { create(:group) }
|
2017-01-26 17:44:58 -05:00
|
|
|
let(:project1) { create(:empty_project, group: group) }
|
|
|
|
let(:project2) { create(:empty_project, path: 'gitlab-ci', group: group) }
|
|
|
|
let(:project3) { create(:empty_project, path: 'cookbook-gitlab', group: group) }
|
2015-11-16 08:38:34 -05:00
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '.build_collection' do
|
2017-01-06 07:47:18 -05:00
|
|
|
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-16 08:38:34 -05:00
|
|
|
before do
|
2017-01-06 07:47:18 -05:00
|
|
|
projects = [
|
|
|
|
project1,
|
|
|
|
project2,
|
|
|
|
project3
|
|
|
|
]
|
2015-11-16 08:38:34 -05:00
|
|
|
|
2017-01-06 07:47:18 -05:00
|
|
|
@global_milestones = GlobalMilestone.build_collection(projects, {})
|
2015-11-16 08:38:34 -05:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'has all project milestones' do
|
2015-11-16 08:38:34 -05:00
|
|
|
expect(@global_milestones.count).to eq(2)
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'has all project milestones titles' do
|
2015-11-16 08:38:34 -05:00
|
|
|
expect(@global_milestones.map(&:title)).to match_array(['Milestone v1.2', 'VD-123'])
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'has all project milestones' do
|
2015-11-16 08:38:34 -05:00
|
|
|
expect(@global_milestones.map { |group_milestone| group_milestone.milestones.count }.sum).to eq(6)
|
|
|
|
end
|
2017-01-06 07:47:18 -05:00
|
|
|
|
|
|
|
it 'sorts collection by due date' do
|
|
|
|
expect(@global_milestones.map(&:due_date)).to eq [nil, milestone1_due_date]
|
|
|
|
end
|
2015-11-16 08:38:34 -05:00
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#initialize' do
|
2017-01-06 07:47:18 -05:00
|
|
|
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-16 08:38:34 -05:00
|
|
|
before do
|
|
|
|
milestones =
|
|
|
|
[
|
|
|
|
milestone1_project1,
|
|
|
|
milestone1_project2,
|
|
|
|
milestone1_project3,
|
|
|
|
]
|
2016-09-23 07:34:39 -04:00
|
|
|
milestones_relation = Milestone.where(id: milestones.map(&:id))
|
2015-11-16 08:38:34 -05:00
|
|
|
|
2016-09-23 07:34:39 -04:00
|
|
|
@global_milestone = GlobalMilestone.new(milestone1_project1.title, milestones_relation)
|
2015-11-16 08:38:34 -05:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'has exactly one group milestone' do
|
2015-11-16 08:38:34 -05:00
|
|
|
expect(@global_milestone.title).to eq('Milestone v1.2')
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'has all project milestones with the same title' do
|
2015-11-16 08:38:34 -05:00
|
|
|
expect(@global_milestone.milestones.count).to eq(3)
|
|
|
|
end
|
|
|
|
end
|
2015-12-22 16:15:32 -05:00
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#safe_title' do
|
2015-12-22 16:15:32 -05:00
|
|
|
let(:milestone) { create(:milestone, title: "git / test", project: project1) }
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'strips out slashes and spaces' do
|
2016-09-23 07:34:39 -04:00
|
|
|
global_milestone = GlobalMilestone.new(milestone.title, Milestone.where(id: milestone.id))
|
2015-12-22 16:15:32 -05:00
|
|
|
|
|
|
|
expect(global_milestone.safe_title).to eq('git-test')
|
|
|
|
end
|
|
|
|
end
|
2015-11-16 08:38:34 -05:00
|
|
|
end
|