2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-16 08:38:34 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe GlobalMilestone do
|
2015-11-16 08:38:34 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let(:group) { create(:group) }
|
2017-08-02 15:55:11 -04:00
|
|
|
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-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
|
|
|
|
|
2018-12-20 06:14:33 -05:00
|
|
|
let!(:projects) do
|
|
|
|
[
|
2017-01-06 07:47:18 -05:00
|
|
|
project1,
|
|
|
|
project2,
|
|
|
|
project3
|
|
|
|
]
|
2015-11-16 08:38:34 -05:00
|
|
|
end
|
|
|
|
|
2018-12-20 06:14:33 -05:00
|
|
|
let!(:global_milestones) { described_class.build_collection(projects, {}) }
|
|
|
|
|
|
|
|
context 'when building a collection of milestones' do
|
|
|
|
it 'has all project milestones' do
|
|
|
|
expect(global_milestones.count).to eq(6)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has all project milestones titles' do
|
|
|
|
expect(global_milestones.map(&:title)).to match_array(['Milestone v1.2', 'Milestone v1.2', 'Milestone v1.2', 'VD-123', 'VD-123', 'VD-123'])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has all project milestones' do
|
|
|
|
expect(global_milestones.size).to eq(6)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts collection by due date' do
|
|
|
|
expect(global_milestones.map(&:due_date)).to eq [milestone1_due_date, milestone1_due_date, milestone1_due_date, nil, nil, nil]
|
|
|
|
end
|
2019-01-17 09:35:23 -05:00
|
|
|
|
|
|
|
it 'filters milestones by search_title when params[:search_title] is present' do
|
|
|
|
global_milestones = described_class.build_collection(projects, { search_title: 'v1.2' })
|
|
|
|
|
|
|
|
expect(global_milestones.map(&:title)).to match_array(['Milestone v1.2', 'Milestone v1.2', 'Milestone v1.2'])
|
|
|
|
end
|
2015-11-16 08:38:34 -05:00
|
|
|
end
|
|
|
|
|
2018-12-20 06:14:33 -05:00
|
|
|
context 'when adding new milestones' do
|
|
|
|
it 'does not add more queries' do
|
|
|
|
control_count = ActiveRecord::QueryRecorder.new do
|
|
|
|
described_class.build_collection(projects, {})
|
|
|
|
end.count
|
|
|
|
|
|
|
|
create_list(:milestone, 3, project: project3)
|
|
|
|
|
|
|
|
expect do
|
|
|
|
described_class.build_collection(projects, {})
|
|
|
|
end.not_to exceed_all_query_limit(control_count)
|
|
|
|
end
|
2015-11-16 08:38:34 -05:00
|
|
|
end
|
2018-12-20 06:14:33 -05:00
|
|
|
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)
|
|
|
|
create(:closed_milestone, title: 'Closed Group Milestone 4', group: group)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the quantity of global milestones and group milestones in each possible state' do
|
|
|
|
expected_count = { opened: 2, closed: 5, all: 7 }
|
2015-11-16 08:38:34 -05:00
|
|
|
|
2018-12-20 06:14:33 -05:00
|
|
|
count = described_class.states_count(Project.all, group)
|
|
|
|
|
|
|
|
expect(count).to eq(expected_count)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the quantity of global milestones in each possible state' do
|
|
|
|
expected_count = { opened: 2, closed: 4, all: 6 }
|
|
|
|
|
|
|
|
count = described_class.states_count(Project.all)
|
|
|
|
|
|
|
|
expect(count).to eq(expected_count)
|
|
|
|
end
|
2015-11-16 08:38:34 -05:00
|
|
|
end
|
2017-01-06 07:47:18 -05:00
|
|
|
|
2018-12-20 06:14:33 -05:00
|
|
|
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 }
|
|
|
|
|
|
|
|
count = described_class.states_count(Project.all)
|
|
|
|
|
|
|
|
expect(count).to eq(expected_count)
|
|
|
|
end
|
2017-01-06 07:47:18 -05:00
|
|
|
end
|
2016-12-12 23:29:12 -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) }
|
2019-12-18 19:08:01 -05:00
|
|
|
|
2018-12-20 06:14:33 -05:00
|
|
|
subject(:global_milestone) { described_class.new(milestone1_project1) }
|
2015-11-16 08:38:34 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'has exactly one group milestone' do
|
2018-12-20 06:14:33 -05:00
|
|
|
expect(global_milestone.title).to eq('Milestone v1.2')
|
2015-11-16 08:38:34 -05:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'has all project milestones with the same title' do
|
2018-12-20 06:14:33 -05:00
|
|
|
expect(global_milestone.milestone).to eq(milestone1_project1)
|
2015-11-16 08:38:34 -05:00
|
|
|
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
|
2018-12-20 06:14:33 -05:00
|
|
|
global_milestone = described_class.new(milestone)
|
2015-12-22 16:15:32 -05:00
|
|
|
|
|
|
|
expect(global_milestone.safe_title).to eq('git-test')
|
|
|
|
end
|
|
|
|
end
|
2016-12-12 23:29:12 -05:00
|
|
|
|
|
|
|
describe '#state' do
|
|
|
|
context 'when at least one milestone is active' do
|
|
|
|
it 'returns active' do
|
|
|
|
title = 'Active Group Milestone'
|
2018-12-20 06:14:33 -05:00
|
|
|
|
|
|
|
global_milestone = described_class.new(create(:active_milestone, title: title))
|
2016-12-12 23:29:12 -05:00
|
|
|
|
|
|
|
expect(global_milestone.state).to eq('active')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when all milestones are closed' do
|
|
|
|
it 'returns closed' do
|
|
|
|
title = 'Closed Group Milestone'
|
2018-12-20 06:14:33 -05:00
|
|
|
|
|
|
|
global_milestone = described_class.new(create(:closed_milestone, title: title))
|
2016-12-12 23:29:12 -05:00
|
|
|
|
|
|
|
expect(global_milestone.state).to eq('closed')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-11-16 08:38:34 -05:00
|
|
|
end
|