2015-09-11 14:41:01 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::MilestonesController do
|
2018-12-13 13:39:08 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2015-09-11 14:41:01 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:milestone) { create(:milestone, project: project) }
|
|
|
|
let(:issue) { create(:issue, project: project, milestone: milestone) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let!(:label) { create(:label, project: project, title: 'Issue Label', issues: [issue]) }
|
2015-12-23 02:04:40 +05:30
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: milestone) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:milestone_path) { namespace_project_milestone_path }
|
2015-09-11 14:41:01 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(user)
|
2015-09-11 14:41:01 +05:30
|
|
|
controller.instance_variable_set(:@project, project)
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it_behaves_like 'milestone tabs'
|
|
|
|
|
|
|
|
describe "#show" do
|
|
|
|
render_views
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
def view_milestone(options = {})
|
|
|
|
params = { namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid }
|
2019-02-15 15:39:39 +05:30
|
|
|
get :show, params: params.merge(options)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows milestone page' do
|
|
|
|
view_milestone
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2018-05-09 12:01:36 +05:30
|
|
|
expect(response.content_type).to eq 'text/html'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns milestone json' do
|
|
|
|
view_milestone format: :json
|
|
|
|
|
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
expect(response.content_type).to eq 'application/json'
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe "#index" do
|
|
|
|
context "as html" do
|
2019-03-02 22:35:43 +05:30
|
|
|
def render_index(project:, page:, search_title: '')
|
2019-02-15 15:39:39 +05:30
|
|
|
get :index, params: {
|
|
|
|
namespace_id: project.namespace.id,
|
|
|
|
project_id: project.id,
|
2019-03-02 22:35:43 +05:30
|
|
|
search_title: search_title,
|
2019-02-15 15:39:39 +05:30
|
|
|
page: page
|
|
|
|
}
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "queries only projects milestones" do
|
2018-11-18 11:00:15 +05:30
|
|
|
render_index project: project, page: 1
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
milestones = assigns(:milestones)
|
|
|
|
|
|
|
|
expect(milestones.count).to eq(1)
|
|
|
|
expect(milestones.where(project_id: nil)).to be_empty
|
|
|
|
end
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
it 'searches milestones by title when search_title is given' do
|
|
|
|
milestone1 = create(:milestone, title: 'Project milestone title', project: project)
|
|
|
|
|
|
|
|
render_index project: project, page: 1, search_title: 'Project mile'
|
|
|
|
|
|
|
|
milestones = assigns(:milestones)
|
|
|
|
expect(milestones).to eq([milestone1])
|
|
|
|
end
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
it 'renders paginated milestones without missing or duplicates' do
|
|
|
|
allow(Milestone).to receive(:default_per_page).and_return(2)
|
|
|
|
create_list(:milestone, 5, project: project)
|
|
|
|
|
|
|
|
render_index project: project, page: 1
|
|
|
|
page_1_milestones = assigns(:milestones)
|
|
|
|
expect(page_1_milestones.size).to eq(2)
|
|
|
|
|
|
|
|
render_index project: project, page: 2
|
|
|
|
page_2_milestones = assigns(:milestones)
|
|
|
|
expect(page_2_milestones.size).to eq(2)
|
|
|
|
|
|
|
|
render_index project: project, page: 3
|
|
|
|
page_3_milestones = assigns(:milestones)
|
|
|
|
expect(page_3_milestones.size).to eq(2)
|
|
|
|
|
|
|
|
rendered_milestone_ids =
|
|
|
|
page_1_milestones.pluck(:id) +
|
|
|
|
page_2_milestones.pluck(:id) +
|
|
|
|
page_3_milestones.pluck(:id)
|
|
|
|
|
|
|
|
expect(rendered_milestone_ids)
|
|
|
|
.to match_array(project.milestones.pluck(:id))
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context "as json" do
|
|
|
|
let!(:group) { create(:group, :public) }
|
|
|
|
let!(:group_milestone) { create(:milestone, group: group) }
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
context 'with a single group ancestor' do
|
|
|
|
before do
|
|
|
|
project.update(namespace: group)
|
2019-02-15 15:39:39 +05:30
|
|
|
get :index, params: { namespace_id: project.namespace.id, project_id: project.id }, format: :json
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "queries projects milestones and groups milestones" do
|
|
|
|
milestones = assigns(:milestones)
|
|
|
|
|
|
|
|
expect(milestones.count).to eq(2)
|
|
|
|
expect(milestones).to match_array([milestone, group_milestone])
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
context 'with nested groups', :nested_groups do
|
|
|
|
let!(:subgroup) { create(:group, :public, parent: group) }
|
|
|
|
let!(:subgroup_milestone) { create(:milestone, group: subgroup) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.update(namespace: subgroup)
|
2019-02-15 15:39:39 +05:30
|
|
|
get :index, params: { namespace_id: project.namespace.id, project_id: project.id }, format: :json
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "queries projects milestones and all ancestors milestones" do
|
|
|
|
milestones = assigns(:milestones)
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(milestones.count).to eq(3)
|
|
|
|
expect(milestones).to match_array([milestone, group_milestone, subgroup_milestone])
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
describe "#destroy" do
|
2016-09-13 17:45:13 +05:30
|
|
|
it "removes milestone" do
|
2015-09-11 14:41:01 +05:30
|
|
|
expect(issue.milestone_id).to eq(milestone.id)
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
delete :destroy, params: { namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid }, format: :js
|
2015-09-11 14:41:01 +05:30
|
|
|
expect(response).to be_success
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(Event.recent.first.action).to eq(Event::DESTROYED)
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
expect { Milestone.find(milestone.id) }.to raise_exception(ActiveRecord::RecordNotFound)
|
|
|
|
issue.reload
|
|
|
|
expect(issue.milestone_id).to eq(nil)
|
2015-09-25 12:07:36 +05:30
|
|
|
|
|
|
|
merge_request.reload
|
|
|
|
expect(merge_request.milestone_id).to eq(nil)
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
# Check system note left for milestone removal
|
|
|
|
last_note = project.issues.find(issue.id).notes[-1].note
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(last_note).to eq('removed milestone')
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe '#promote' do
|
2018-11-29 20:51:05 +05:30
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.update(namespace: group)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user does not have permission to promote milestone' do
|
|
|
|
before do
|
|
|
|
group.add_guest(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders 404' do
|
2019-02-15 15:39:39 +05:30
|
|
|
post :promote, params: { namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid }
|
2018-11-29 20:51:05 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-05 12:25:43 +05:30
|
|
|
describe '#labels' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
context 'as json' do
|
|
|
|
let!(:guest) { create(:user, username: 'guest1') }
|
|
|
|
let!(:group) { create(:group, :public) }
|
|
|
|
let!(:project) { create(:project, :public, group: group) }
|
|
|
|
let!(:label) { create(:label, title: 'test_label_on_private_issue', project: project) }
|
|
|
|
let!(:confidential_issue) { create(:labeled_issue, confidential: true, project: project, milestone: milestone, labels: [label]) }
|
|
|
|
|
|
|
|
it 'does not render labels of private issues if user has no access' do
|
|
|
|
sign_in(guest)
|
|
|
|
|
|
|
|
get :labels, params: { namespace_id: group.id, project_id: project.id, id: milestone.iid }, format: :json
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(response.content_type).to eq 'application/json'
|
|
|
|
|
|
|
|
expect(json_response['html']).not_to include(label.title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does render labels of private issues if user has access' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get :labels, params: { namespace_id: group.id, project_id: project.id, id: milestone.iid }, format: :json
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(response.content_type).to eq 'application/json'
|
|
|
|
|
|
|
|
expect(json_response['html']).to include(label.title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'promotion succeeds' do
|
|
|
|
before do
|
|
|
|
group.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows group milestone' do
|
2019-02-15 15:39:39 +05:30
|
|
|
post :promote, params: { namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(flash[:notice]).to eq("#{milestone.title} promoted to <a href=\"#{group_milestone_path(project.group, milestone.iid)}\"><u>group milestone</u></a>.")
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(response).to redirect_to(project_milestones_path(project))
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders milestone name without parsing it as HTML' do
|
|
|
|
milestone.update!(name: 'CCC<img src=x onerror=alert(document.domain)>')
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
post :promote, params: { namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid }
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(flash[:notice]).to eq("CCC promoted to <a href=\"#{group_milestone_path(project.group, milestone.iid)}\"><u>group milestone</u></a>.")
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-29 20:51:05 +05:30
|
|
|
context 'when user cannot admin group milestones' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders 404' do
|
|
|
|
project.update(namespace: user.namespace)
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
post :promote, params: { namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-29 20:51:05 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|