summaryrefslogtreecommitdiff
path: root/spec/services/delete_merged_branches_service_spec.rb
diff options
context:
space:
mode:
authorToon Claes <toon@iotcl.com>2016-09-21 16:15:12 +0200
committerToon Claes <toon@iotcl.com>2016-11-09 21:04:03 +0100
commit1afab9eb79c87f32c7b899e58bc9a0ea8a113594 (patch)
tree33068aabffdb6b76c0489246429a3a71c2b748a4 /spec/services/delete_merged_branches_service_spec.rb
parentc392b0cc24ba40e3fed920c6c693cb24665193af (diff)
downloadgitlab-ce-1afab9eb79c87f32c7b899e58bc9a0ea8a113594.tar.gz
Add button to delete all merged branches
It adds a button to the branches page that the user can use to delete all the branches that are already merged. This can be used to clean up all the branches that were forgotten to delete while merging MRs. Fixes #21076.
Diffstat (limited to 'spec/services/delete_merged_branches_service_spec.rb')
-rw-r--r--spec/services/delete_merged_branches_service_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/services/delete_merged_branches_service_spec.rb b/spec/services/delete_merged_branches_service_spec.rb
new file mode 100644
index 00000000000..181488e89c7
--- /dev/null
+++ b/spec/services/delete_merged_branches_service_spec.rb
@@ -0,0 +1,54 @@
+require 'spec_helper'
+
+describe DeleteMergedBranchesService, services: true do
+ subject(:service) { described_class.new(project, project.owner) }
+
+ let(:project) { create(:project) }
+
+ context '#execute' do
+ context 'unprotected branches' do
+ before do
+ service.execute
+ end
+
+ it 'deletes a branch that was merged' do
+ expect(project.repository.branch_names).not_to include('improve/awesome')
+ end
+
+ it 'keeps branch that is unmerged' do
+ expect(project.repository.branch_names).to include('feature')
+ end
+
+ it 'keeps "master"' do
+ expect(project.repository.branch_names).to include('master')
+ end
+ end
+
+ context 'protected branches' do
+ before do
+ create(:protected_branch, name: 'improve/awesome', project: project)
+ service.execute
+ end
+
+ it 'keeps protected branch' do
+ expect(project.repository.branch_names).to include('improve/awesome')
+ end
+ end
+
+ 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
+ end
+
+ context '#async_execute' do
+ it 'calls DeleteMergedBranchesWorker async' do
+ expect(DeleteMergedBranchesWorker).to receive(:perform_async)
+
+ service.async_execute
+ end
+ end
+end