summaryrefslogtreecommitdiff
path: root/spec/models/repository_spec.rb
diff options
context:
space:
mode:
authorGitLab Release Tools Bot <delivery-team+release-tools@gitlab.com>2022-07-28 13:33:09 +0000
committerGitLab Release Tools Bot <delivery-team+release-tools@gitlab.com>2022-07-28 13:33:09 +0000
commit328ff31ff9e6147e4fb883aaee113001da150b9e (patch)
treee1c4c45aa86e7d3f3da88030b892764fff3bc0ff /spec/models/repository_spec.rb
parent4dc46d5b97305108c1b635baa4241a2ce04a7ed0 (diff)
parentf415ebdb978c4eb976d07664219c788918120d59 (diff)
downloadgitlab-ce-15-0-stable.tar.gz
Merge remote-tracking branch 'dev/15-0-stable' into 15-0-stable15-0-stable
Diffstat (limited to 'spec/models/repository_spec.rb')
-rw-r--r--spec/models/repository_spec.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 215f83adf5d..e24adc20143 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -3375,4 +3375,62 @@ RSpec.describe Repository do
end
end
end
+
+ describe '#remove_prohibited_branches' do
+ let(:branch_name) { '37fd3601be4c25497a39fa2e6a206e09e759d597' }
+
+ before do
+ allow(repository.raw_repository).to receive(:branch_names).and_return([branch_name])
+ end
+
+ context 'when prohibited branch exists' do
+ it 'deletes prohibited branch' do
+ expect(repository.raw_repository).to receive(:delete_branch).with(branch_name)
+
+ repository.remove_prohibited_branches
+ end
+ end
+
+ shared_examples 'does not delete branch' do
+ it 'returns without removing the branch' do
+ expect(repository.raw_repository).not_to receive(:delete_branch)
+
+ repository.remove_prohibited_branches
+ end
+ end
+
+ context 'when branch name is 40-characters long but not hexadecimal' do
+ let(:branch_name) { '37fd3601be4c25497a39fa2e6a206e09e759d59s' }
+
+ include_examples 'does not delete branch'
+ end
+
+ context 'when branch name is hexadecimal' do
+ context 'when branch name is less than 40-characters long' do
+ let(:branch_name) { '37fd3601be4c25497a39fa2e6a206e09e759d' }
+
+ include_examples 'does not delete branch'
+ end
+
+ context 'when branch name is more than 40-characters long' do
+ let(:branch_name) { '37fd3601be4c25497a39fa2e6a206e09e759dfdfd' }
+
+ include_examples 'does not delete branch'
+ end
+ end
+
+ context 'when prohibited branch does not exist' do
+ let(:branch_name) { 'main' }
+
+ include_examples 'does not delete branch'
+ end
+
+ context 'when raw repository does not exist' do
+ before do
+ allow(repository).to receive(:exists?).and_return(false)
+ end
+
+ include_examples 'does not delete branch'
+ end
+ end
end