2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
describe Branches::DeleteMergedService do
|
2018-03-17 18:26:18 +05:30
|
|
|
include ProjectForksHelper
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
subject(:service) { described_class.new(project, project.owner) }
|
|
|
|
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe '#execute' do
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'deletes a branch that was merged' do
|
|
|
|
service.execute
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(project.repository.branch_names).not_to include('improve/awesome')
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'keeps branch that is unmerged' do
|
|
|
|
service.execute
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(project.repository.branch_names).to include('feature')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'keeps "master"' do
|
|
|
|
service.execute
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(project.repository.branch_names).to include('master')
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
it 'keeps wildcard protected branches' do
|
|
|
|
create(:protected_branch, project: project, name: 'improve/*')
|
|
|
|
|
|
|
|
service.execute
|
|
|
|
|
|
|
|
expect(project.repository.branch_names).to include('improve/awesome')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
|
|
|
|
|
|
|
context 'open merge requests' do
|
|
|
|
it 'does not delete branches from open merge requests' do
|
2018-03-17 18:26:18 +05:30
|
|
|
forked_project = fork_project(project)
|
2017-09-10 17:25:29 +05:30
|
|
|
create(:merge_request, :opened, source_project: project, target_project: project, source_branch: 'branch-merged', target_branch: 'master')
|
2018-03-17 18:26:18 +05:30
|
|
|
create(:merge_request, :opened, source_project: forked_project, target_project: project, target_branch: 'improve/awesome', source_branch: 'master')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
service.execute
|
|
|
|
|
|
|
|
expect(project.repository.branch_names).to include('branch-merged')
|
|
|
|
expect(project.repository.branch_names).to include('improve/awesome')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe '#async_execute' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'calls DeleteMergedBranchesWorker async' do
|
|
|
|
expect(DeleteMergedBranchesWorker).to receive(:perform_async)
|
|
|
|
|
|
|
|
service.async_execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|