2019-04-15 10:17:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-08 16:43:05 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Dashboard::MilestonesController do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2018-08-03 19:52:37 +00:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:user) { create(:user) }
|
2017-06-08 16:43:05 +00:00
|
|
|
let(:project_milestone) { create(:milestone, project: project) }
|
2018-08-03 19:52:37 +00:00
|
|
|
let(:group_milestone) { create(:milestone, group: group) }
|
2017-06-08 16:43:05 +00:00
|
|
|
let(:milestone) do
|
|
|
|
DashboardMilestone.build(
|
|
|
|
[project],
|
|
|
|
project_milestone.title
|
|
|
|
)
|
|
|
|
end
|
|
|
|
let(:issue) { create(:issue, project: project, milestone: project_milestone) }
|
2019-01-14 10:46:39 +00:00
|
|
|
let(:group_issue) { create(:issue, milestone: group_milestone, project: create(:project, group: group)) }
|
2018-08-03 19:52:37 +00:00
|
|
|
|
2017-06-08 16:43:05 +00:00
|
|
|
let!(:label) { create(:label, project: project, title: 'Issue Label', issues: [issue]) }
|
2018-08-03 19:52:37 +00:00
|
|
|
let!(:group_label) { create(:group_label, group: group, title: 'Group Issue Label', issues: [group_issue]) }
|
2017-06-08 16:43:05 +00:00
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: project_milestone) }
|
|
|
|
let(:milestone_path) { dashboard_milestone_path(milestone.safe_title, title: milestone.title) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2018-08-03 19:52:37 +00:00
|
|
|
group.add_developer(user)
|
2017-06-08 16:43:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'milestone tabs'
|
|
|
|
|
|
|
|
describe "#show" do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
def view_milestone
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { id: milestone.safe_title, title: milestone.title }
|
2017-06-08 16:43:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows milestone page' do
|
|
|
|
view_milestone
|
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-06-08 16:43:05 +00:00
|
|
|
end
|
|
|
|
end
|
2018-08-03 19:52:37 +00:00
|
|
|
|
|
|
|
describe "#index" do
|
2019-02-14 05:45:30 +00:00
|
|
|
let(:public_group) { create(:group, :public) }
|
|
|
|
let!(:public_milestone) { create(:milestone, group: public_group) }
|
2019-07-17 16:34:42 +00:00
|
|
|
let!(:closed_group_milestone) { create(:milestone, group: group, state: 'closed') }
|
|
|
|
let!(:closed_project_milestone) { create(:milestone, project: project, state: 'closed') }
|
2019-02-14 05:45:30 +00:00
|
|
|
|
2018-10-03 13:19:13 +00:00
|
|
|
render_views
|
|
|
|
|
2018-09-11 00:37:21 +00:00
|
|
|
it 'returns group and project milestones to which the user belongs' do
|
2018-08-03 19:52:37 +00:00
|
|
|
get :index, format: :json
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(json_response.size).to eq(2)
|
2018-12-20 11:14:33 +00:00
|
|
|
expect(json_response.map { |i| i["name"] }).to match_array([group_milestone.name, project_milestone.name])
|
2018-09-11 00:37:21 +00:00
|
|
|
expect(json_response.map { |i| i["group_name"] }.compact).to match_array(group.name)
|
2018-08-03 19:52:37 +00:00
|
|
|
end
|
2018-10-03 13:19:13 +00:00
|
|
|
|
2019-07-16 21:33:35 +00:00
|
|
|
it 'returns closed group and project milestones to which the user belongs' do
|
|
|
|
get :index, params: { state: 'closed' }, format: :json
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(json_response.size).to eq(2)
|
|
|
|
expect(json_response.map { |i| i["name"] }).to match_array([closed_group_milestone.name, closed_project_milestone.name])
|
|
|
|
expect(json_response.map { |i| i["group_name"] }.compact).to match_array(group.name)
|
|
|
|
end
|
|
|
|
|
2019-01-17 14:35:23 +00:00
|
|
|
it 'searches legacy project milestones by title when search_title is given' do
|
|
|
|
project_milestone = create(:milestone, title: 'Project milestone title', project: project)
|
|
|
|
|
|
|
|
get :index, params: { search_title: 'Project mil' }
|
|
|
|
|
|
|
|
expect(response.body).to include(project_milestone.title)
|
|
|
|
expect(response.body).not_to include(group_milestone.title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'searches group milestones by title when search_title is given' do
|
|
|
|
group_milestone = create(:milestone, title: 'Group milestone title', group: group)
|
|
|
|
|
|
|
|
get :index, params: { search_title: 'Group mil' }
|
|
|
|
|
|
|
|
expect(response.body).to include(group_milestone.title)
|
|
|
|
expect(response.body).not_to include(project_milestone.title)
|
|
|
|
end
|
|
|
|
|
2019-07-17 16:34:42 +00:00
|
|
|
it 'shows counts of open and closed group and project milestones to which the user belongs to' do
|
2019-07-16 21:33:35 +00:00
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(response.body).to include("Open\n<span class=\"badge badge-pill\">2</span>")
|
|
|
|
expect(response.body).to include("Closed\n<span class=\"badge badge-pill\">2</span>")
|
|
|
|
end
|
|
|
|
|
2019-04-09 15:38:58 +00:00
|
|
|
context 'external authorization' do
|
|
|
|
subject { get :index }
|
|
|
|
|
|
|
|
it_behaves_like 'disabled when using an external authorization service'
|
|
|
|
end
|
2018-08-03 19:52:37 +00:00
|
|
|
end
|
2017-06-08 16:43:05 +00:00
|
|
|
end
|