2015-07-14 18:20:38 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::MilestonesController do
|
2018-10-25 09:48:03 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2015-07-14 18:20:38 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:milestone) { create(:milestone, project: project) }
|
|
|
|
let(:issue) { create(:issue, project: project, milestone: milestone) }
|
2017-04-24 11:58:15 -04:00
|
|
|
let!(:label) { create(:label, project: project, title: 'Issue Label', issues: [issue]) }
|
2015-12-05 01:56:10 -05:00
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: milestone) }
|
2017-04-26 06:32:21 -04:00
|
|
|
let(:milestone_path) { namespace_project_milestone_path }
|
2015-07-14 18:20:38 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2015-07-14 18:20:38 -04:00
|
|
|
controller.instance_variable_set(:@project, project)
|
|
|
|
end
|
|
|
|
|
2017-04-26 06:32:21 -04:00
|
|
|
it_behaves_like 'milestone tabs'
|
|
|
|
|
2017-04-24 11:58:15 -04:00
|
|
|
describe "#show" do
|
|
|
|
render_views
|
|
|
|
|
2017-06-17 02:40:12 -04:00
|
|
|
def view_milestone(options = {})
|
|
|
|
params = { namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid }
|
|
|
|
get :show, params.merge(options)
|
2017-04-24 11:58:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows milestone page' do
|
|
|
|
view_milestone
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-06-17 02:40:12 -04:00
|
|
|
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-04-24 11:58:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-07 11:08:49 -04:00
|
|
|
describe "#index" do
|
|
|
|
context "as html" do
|
2018-08-06 15:38:37 -04:00
|
|
|
def render_index(project:, page:)
|
|
|
|
get :index, namespace_id: project.namespace.id,
|
|
|
|
project_id: project.id,
|
|
|
|
page: page
|
2017-07-07 11:08:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "queries only projects milestones" do
|
2018-08-06 15:38:37 -04:00
|
|
|
render_index project: project, page: 1
|
|
|
|
|
2017-07-07 11:08:49 -04:00
|
|
|
milestones = assigns(:milestones)
|
|
|
|
|
|
|
|
expect(milestones.count).to eq(1)
|
|
|
|
expect(milestones.where(project_id: nil)).to be_empty
|
|
|
|
end
|
2018-08-06 15:38:37 -04:00
|
|
|
|
|
|
|
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-07-07 11:08:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "as json" do
|
|
|
|
let!(:group) { create(:group, :public) }
|
|
|
|
let!(:group_milestone) { create(:milestone, group: group) }
|
|
|
|
|
2018-06-01 03:52:55 -04:00
|
|
|
context 'with a single group ancestor' do
|
|
|
|
before do
|
|
|
|
project.update(namespace: group)
|
|
|
|
get :index, namespace_id: project.namespace.id, project_id: project.id, format: :json
|
|
|
|
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-07-07 11:08:49 -04:00
|
|
|
end
|
|
|
|
|
2018-06-01 03:52:55 -04:00
|
|
|
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)
|
|
|
|
get :index, namespace_id: project.namespace.id, project_id: project.id, format: :json
|
|
|
|
end
|
|
|
|
|
|
|
|
it "queries projects milestones and all ancestors milestones" do
|
|
|
|
milestones = assigns(:milestones)
|
2017-07-07 11:08:49 -04:00
|
|
|
|
2018-06-01 03:52:55 -04:00
|
|
|
expect(milestones.count).to eq(3)
|
|
|
|
expect(milestones).to match_array([milestone, group_milestone, subgroup_milestone])
|
|
|
|
end
|
2017-07-07 11:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-14 18:20:38 -04:00
|
|
|
describe "#destroy" do
|
2016-07-25 14:16:19 -04:00
|
|
|
it "removes milestone" do
|
2015-07-14 18:20:38 -04:00
|
|
|
expect(issue.milestone_id).to eq(milestone.id)
|
2015-08-31 00:51:34 -04:00
|
|
|
|
2015-12-05 01:56:10 -05:00
|
|
|
delete :destroy, namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid, format: :js
|
2015-07-14 18:20:38 -04:00
|
|
|
expect(response).to be_success
|
2015-08-31 00:51:34 -04:00
|
|
|
|
2016-10-27 00:48:26 -04:00
|
|
|
expect(Event.recent.first.action).to eq(Event::DESTROYED)
|
2015-08-31 00:51:34 -04:00
|
|
|
|
2015-07-14 18:20:38 -04:00
|
|
|
expect { Milestone.find(milestone.id) }.to raise_exception(ActiveRecord::RecordNotFound)
|
|
|
|
issue.reload
|
|
|
|
expect(issue.milestone_id).to eq(nil)
|
2015-09-18 11:39:19 -04:00
|
|
|
|
|
|
|
merge_request.reload
|
|
|
|
expect(merge_request.milestone_id).to eq(nil)
|
|
|
|
|
2015-07-14 18:20:38 -04:00
|
|
|
# Check system note left for milestone removal
|
|
|
|
last_note = project.issues.find(issue.id).notes[-1].note
|
2016-11-23 01:55:23 -05:00
|
|
|
expect(last_note).to eq('removed milestone')
|
2015-07-14 18:20:38 -04:00
|
|
|
end
|
|
|
|
end
|
2017-10-31 11:03:52 -04:00
|
|
|
|
|
|
|
describe '#promote' do
|
2018-11-28 13:38:24 -05:00
|
|
|
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
|
|
|
|
post :promote, namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-31 11:03:52 -04:00
|
|
|
context 'promotion succeeds' do
|
|
|
|
before do
|
|
|
|
group.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows group milestone' do
|
|
|
|
post :promote, namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid
|
|
|
|
|
2018-06-21 17:14:46 -04:00
|
|
|
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-01 17:09:25 -05:00
|
|
|
expect(response).to redirect_to(project_milestones_path(project))
|
2017-10-31 11:03:52 -04:00
|
|
|
end
|
2018-07-12 10:58:33 -04:00
|
|
|
|
|
|
|
it 'renders milestone name without parsing it as HTML' do
|
|
|
|
milestone.update!(name: 'CCC<img src=x onerror=alert(document.domain)>')
|
|
|
|
|
|
|
|
post :promote, namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid
|
|
|
|
|
2018-07-16 06:49:01 -04:00
|
|
|
expect(flash[:notice]).to eq("CCC promoted to <a href=\"#{group_milestone_path(project.group, milestone.iid)}\"><u>group milestone</u></a>.")
|
2018-07-12 10:58:33 -04:00
|
|
|
end
|
2017-10-31 11:03:52 -04:00
|
|
|
end
|
|
|
|
|
2018-11-28 13:38:24 -05:00
|
|
|
context 'when user cannot admin group milestones' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders 404' do
|
|
|
|
project.update(namespace: user.namespace)
|
|
|
|
|
2017-10-31 11:03:52 -04:00
|
|
|
post :promote, namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid
|
|
|
|
|
2018-11-28 13:38:24 -05:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-10-31 11:03:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-07-14 18:20:38 -04:00
|
|
|
end
|