debian-mirror-gitlab/spec/services/milestones/destroy_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.4 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Milestones::DestroyService do
2017-09-10 17:25:29 +05:30
let(:user) { create(:user) }
2018-12-13 13:39:08 +05:30
let(:project) { create(:project, :repository) }
2017-09-10 17:25:29 +05:30
let(:milestone) { create(:milestone, title: 'Milestone v1.0', project: project) }
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2017-09-10 17:25:29 +05:30
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
2021-04-29 21:17:54 +05:30
context 'with an existing merge request' do
let!(:issue) { create(:issue, project: project, milestone: milestone) }
let!(:merge_request) { create(:merge_request, source_project: project, milestone: milestone) }
2018-11-20 20:47:30 +05:30
2021-04-29 21:17:54 +05:30
it 'deletes milestone id from issuables' do
service.execute(milestone)
2017-09-10 17:25:29 +05:30
2021-04-29 21:17:54 +05:30
expect(issue.reload.milestone).to be_nil
expect(merge_request.reload.milestone).to be_nil
end
2017-09-10 17:25:29 +05:30
end
2018-11-20 20:47:30 +05:30
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-09-10 17:25:29 +05:30
context 'group milestones' do
let(:group) { create(:group) }
let(:group_milestone) { create(:milestone, group: group) }
before do
2021-01-03 14:25:43 +05:30
project.update!(namespace: group)
2017-09-10 17:25:29 +05:30
group.add_developer(user)
end
2018-11-20 20:47:30 +05:30
it { expect(service.execute(group_milestone)).to eq(group_milestone) }
2017-09-10 17:25:29 +05:30
2018-11-20 20:47:30 +05:30
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-09-10 17:25:29 +05:30
service.execute(group_milestone)
2018-11-20 20:47:30 +05:30
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-09-10 17:25:29 +05:30
end
end
2019-12-04 20:38:33 +05:30
context 'when a release is tied to a milestone' do
it 'destroys the milestone but not the associated release' do
release = create(
:release,
tag: 'v1.0',
project: project,
milestones: [milestone]
)
expect { service.execute(milestone) }.not_to change { Release.count }
expect(release.reload).to be_persisted
end
end
2017-09-10 17:25:29 +05:30
end
end