2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-21 10:15:12 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe DeleteMergedBranchesService do
|
2017-09-29 04:04:50 -04:00
|
|
|
include ProjectForksHelper
|
|
|
|
|
2016-09-21 10:15:12 -04:00
|
|
|
subject(:service) { described_class.new(project, project.owner) }
|
|
|
|
|
2017-03-27 17:14:01 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-09-21 10:15:12 -04:00
|
|
|
|
|
|
|
context '#execute' do
|
2017-05-08 03:41:58 -04:00
|
|
|
it 'deletes a branch that was merged' do
|
|
|
|
service.execute
|
|
|
|
|
|
|
|
expect(project.repository.branch_names).not_to include('improve/awesome')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'keeps branch that is unmerged' do
|
|
|
|
service.execute
|
|
|
|
|
|
|
|
expect(project.repository.branch_names).to include('feature')
|
2016-09-21 10:15:12 -04:00
|
|
|
end
|
|
|
|
|
2017-05-08 03:41:58 -04:00
|
|
|
it 'keeps "master"' do
|
|
|
|
service.execute
|
2016-09-21 10:15:12 -04:00
|
|
|
|
2017-05-08 03:41:58 -04:00
|
|
|
expect(project.repository.branch_names).to include('master')
|
2016-09-21 10:15:12 -04:00
|
|
|
end
|
|
|
|
|
2017-07-04 05:51:00 -04:00
|
|
|
it 'keeps protected branches' do
|
|
|
|
create(:protected_branch, project: project, name: 'improve/awesome')
|
|
|
|
|
|
|
|
service.execute
|
|
|
|
|
|
|
|
expect(project.repository.branch_names).to include('improve/awesome')
|
|
|
|
end
|
|
|
|
|
2017-08-02 08:40:17 -04:00
|
|
|
it 'keeps wildcard protected branches' do
|
|
|
|
create(:protected_branch, project: project, name: 'improve/*')
|
|
|
|
|
|
|
|
service.execute
|
|
|
|
|
|
|
|
expect(project.repository.branch_names).to include('improve/awesome')
|
|
|
|
end
|
|
|
|
|
2017-11-07 10:49:07 -05:00
|
|
|
it 'ignores protected tags' do
|
|
|
|
create(:protected_tag, project: project, name: 'improve/*')
|
|
|
|
|
|
|
|
service.execute
|
|
|
|
|
|
|
|
expect(project.repository.branch_names).not_to include('improve/awesome')
|
|
|
|
end
|
|
|
|
|
2016-09-21 10:15:12 -04:00
|
|
|
context 'user without rights' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
it 'cannot execute' do
|
|
|
|
expect { described_class.new(project, user).execute }.to raise_error(Gitlab::Access::AccessDeniedError)
|
|
|
|
end
|
|
|
|
end
|
2017-04-16 23:51:16 -04:00
|
|
|
|
|
|
|
context 'open merge requests' do
|
|
|
|
it 'does not delete branches from open merge requests' do
|
2017-09-29 04:04:50 -04:00
|
|
|
forked_project = fork_project(project)
|
2017-07-19 10:03:50 -04:00
|
|
|
create(:merge_request, :opened, source_project: project, target_project: project, source_branch: 'branch-merged', target_branch: 'master')
|
2017-09-29 04:04:50 -04:00
|
|
|
create(:merge_request, :opened, source_project: forked_project, target_project: project, target_branch: 'improve/awesome', source_branch: 'master')
|
2017-04-16 23:51:16 -04:00
|
|
|
|
|
|
|
service.execute
|
|
|
|
|
|
|
|
expect(project.repository.branch_names).to include('branch-merged')
|
|
|
|
expect(project.repository.branch_names).to include('improve/awesome')
|
|
|
|
end
|
|
|
|
end
|
2016-09-21 10:15:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context '#async_execute' do
|
|
|
|
it 'calls DeleteMergedBranchesWorker async' do
|
|
|
|
expect(DeleteMergedBranchesWorker).to receive(:perform_async)
|
|
|
|
|
|
|
|
service.async_execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|