2015-07-14 22:20:38 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::MilestonesController do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2015-07-14 22:20:38 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:milestone) { create(:milestone, project: project) }
|
|
|
|
let(:issue) { create(:issue, project: project, milestone: milestone) }
|
2017-04-24 15:58:15 +00:00
|
|
|
let!(:label) { create(:label, project: project, title: 'Issue Label', issues: [issue]) }
|
2015-12-05 06:56:10 +00:00
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: milestone) }
|
2017-04-26 10:32:21 +00:00
|
|
|
let(:milestone_path) { namespace_project_milestone_path }
|
2015-07-14 22:20:38 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :master]
|
|
|
|
controller.instance_variable_set(:@project, project)
|
|
|
|
end
|
|
|
|
|
2017-04-26 10:32:21 +00:00
|
|
|
it_behaves_like 'milestone tabs'
|
|
|
|
|
2017-04-24 15:58:15 +00:00
|
|
|
describe "#show" do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
def view_milestone
|
|
|
|
get :show, namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid
|
|
|
|
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-04-24 15:58:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-07 15:08:49 +00:00
|
|
|
describe "#index" do
|
|
|
|
context "as html" do
|
|
|
|
before do
|
|
|
|
get :index, namespace_id: project.namespace.id, project_id: project.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it "queries only projects milestones" do
|
|
|
|
milestones = assigns(:milestones)
|
|
|
|
|
|
|
|
expect(milestones.count).to eq(1)
|
|
|
|
expect(milestones.where(project_id: nil)).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "as json" do
|
|
|
|
let!(:group) { create(:group, :public) }
|
|
|
|
let!(:group_milestone) { create(:milestone, group: group) }
|
|
|
|
let!(:group_member) { create(:group_member, group: group, user: user) }
|
|
|
|
|
|
|
|
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.where(project_id: nil).first).to eq(group_milestone)
|
|
|
|
expect(milestones.where(group_id: nil).first).to eq(milestone)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-14 22:20:38 +00:00
|
|
|
describe "#destroy" do
|
2016-07-25 18:16:19 +00:00
|
|
|
it "removes milestone" do
|
2015-07-14 22:20:38 +00:00
|
|
|
expect(issue.milestone_id).to eq(milestone.id)
|
2015-08-31 04:51:34 +00:00
|
|
|
|
2015-12-05 06:56:10 +00:00
|
|
|
delete :destroy, namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid, format: :js
|
2015-07-14 22:20:38 +00:00
|
|
|
expect(response).to be_success
|
2015-08-31 04:51:34 +00:00
|
|
|
|
2016-10-27 04:48:26 +00:00
|
|
|
expect(Event.recent.first.action).to eq(Event::DESTROYED)
|
2015-08-31 04:51:34 +00:00
|
|
|
|
2015-07-14 22:20:38 +00:00
|
|
|
expect { Milestone.find(milestone.id) }.to raise_exception(ActiveRecord::RecordNotFound)
|
|
|
|
issue.reload
|
|
|
|
expect(issue.milestone_id).to eq(nil)
|
2015-09-18 15:39:19 +00:00
|
|
|
|
|
|
|
merge_request.reload
|
|
|
|
expect(merge_request.milestone_id).to eq(nil)
|
|
|
|
|
2015-07-14 22:20:38 +00:00
|
|
|
# Check system note left for milestone removal
|
|
|
|
last_note = project.issues.find(issue.id).notes[-1].note
|
2016-11-23 06:55:23 +00:00
|
|
|
expect(last_note).to eq('removed milestone')
|
2015-07-14 22:20:38 +00:00
|
|
|
end
|
|
|
|
end
|
2017-10-31 15:03:52 +00:00
|
|
|
|
|
|
|
describe '#promote' do
|
|
|
|
context 'promotion succeeds' do
|
|
|
|
before do
|
|
|
|
group = create(:group)
|
|
|
|
group.add_developer(user)
|
|
|
|
milestone.project.update(namespace: group)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows group milestone' do
|
|
|
|
post :promote, namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid
|
|
|
|
|
|
|
|
group_milestone = assigns(:milestone)
|
|
|
|
|
|
|
|
expect(response).to redirect_to(group_milestone_path(project.group, group_milestone.iid))
|
|
|
|
expect(flash[:notice]).to eq('Milestone has been promoted to group milestone.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'promotion fails' do
|
|
|
|
it 'shows project milestone' do
|
|
|
|
post :promote, namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid
|
|
|
|
|
|
|
|
expect(response).to redirect_to(project_milestone_path(project, milestone))
|
|
|
|
expect(flash[:alert]).to eq('Promotion failed - Project does not belong to a group.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-07-14 22:20:38 +00:00
|
|
|
end
|