2017-07-11 02:23:51 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Milestones::DestroyService do
|
2017-07-11 02:23:51 -04:00
|
|
|
let(:user) { create(:user) }
|
2018-10-25 09:48:03 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2017-07-11 02:23:51 -04:00
|
|
|
let(:milestone) { create(:milestone, title: 'Milestone v1.0', project: project) }
|
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-07-11 02:23:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def service
|
|
|
|
described_class.new(project, user, {})
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
it 'deletes milestone' do
|
|
|
|
service.execute(milestone)
|
|
|
|
|
|
|
|
expect { milestone.reload }.to raise_error ActiveRecord::RecordNotFound
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'deletes milestone id from issuables' do
|
2018-08-06 15:02:52 -04:00
|
|
|
issue = create(:issue, project: project, milestone: milestone)
|
|
|
|
merge_request = create(:merge_request, source_project: project, milestone: milestone)
|
|
|
|
|
2017-07-11 02:23:51 -04:00
|
|
|
service.execute(milestone)
|
|
|
|
|
|
|
|
expect(issue.reload.milestone).to be_nil
|
|
|
|
expect(merge_request.reload.milestone).to be_nil
|
|
|
|
end
|
|
|
|
|
2018-08-06 15:02:52 -04:00
|
|
|
it 'logs destroy event' do
|
|
|
|
service.execute(milestone)
|
|
|
|
|
|
|
|
event = Event.where(project_id: milestone.project_id, target_type: 'Milestone')
|
|
|
|
|
|
|
|
expect(event.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
2017-07-11 02:23:51 -04:00
|
|
|
context 'group milestones' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:group_milestone) { create(:milestone, group: group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.update(namespace: group)
|
|
|
|
group.add_developer(user)
|
|
|
|
end
|
|
|
|
|
2018-08-06 15:02:52 -04:00
|
|
|
it { expect(service.execute(group_milestone)).to eq(group_milestone) }
|
2017-07-11 02:23:51 -04:00
|
|
|
|
2018-08-06 15:02:52 -04:00
|
|
|
it 'deletes milestone id from issuables' do
|
|
|
|
issue = create(:issue, project: project, milestone: group_milestone)
|
|
|
|
merge_request = create(:merge_request, source_project: project, milestone: group_milestone)
|
2017-07-11 02:23:51 -04:00
|
|
|
|
|
|
|
service.execute(group_milestone)
|
2018-08-06 15:02:52 -04:00
|
|
|
|
|
|
|
expect(issue.reload.milestone).to be_nil
|
|
|
|
expect(merge_request.reload.milestone).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not log destroy event' do
|
|
|
|
expect { service.execute(group_milestone) }.not_to change { Event.count }
|
2017-07-11 02:23:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|