summaryrefslogtreecommitdiff
path: root/spec/models/protected_tag_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-06-20 11:10:13 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-06-20 11:10:13 +0000
commit0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch)
tree7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/models/protected_tag_spec.rb
parent72123183a20411a36d607d70b12d57c484394c8e (diff)
downloadgitlab-ce-0ea3fcec397b69815975647f5e2aa5fe944a8486.tar.gz
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/models/protected_tag_spec.rb')
-rw-r--r--spec/models/protected_tag_spec.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/models/protected_tag_spec.rb b/spec/models/protected_tag_spec.rb
index e5cee6f18cd..b97954c055d 100644
--- a/spec/models/protected_tag_spec.rb
+++ b/spec/models/protected_tag_spec.rb
@@ -11,4 +11,56 @@ RSpec.describe ProtectedTag do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:name) }
end
+
+ describe '#protected?' do
+ let(:project) { create(:project, :repository) }
+
+ it 'returns true when the tag matches a protected tag via direct match' do
+ create(:protected_tag, project: project, name: 'foo')
+
+ expect(described_class.protected?(project, 'foo')).to eq(true)
+ end
+
+ it 'returns true when the tag matches a protected tag via wildcard match' do
+ create(:protected_tag, project: project, name: 'production/*')
+
+ expect(described_class.protected?(project, 'production/some-tag')).to eq(true)
+ end
+
+ it 'returns false when the tag does not match a protected tag via direct match' do
+ expect(described_class.protected?(project, 'foo')).to eq(false)
+ end
+
+ it 'returns false when the tag does not match a protected tag via wildcard match' do
+ create(:protected_tag, project: project, name: 'production/*')
+
+ expect(described_class.protected?(project, 'staging/some-tag')).to eq(false)
+ end
+
+ it 'returns false when tag name is nil' do
+ expect(described_class.protected?(project, nil)).to eq(false)
+ end
+
+ context 'with caching', :request_store do
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:protected_tag) { create(:protected_tag, project: project, name: 'foo') }
+
+ it 'correctly invalidates a cache' do
+ expect(described_class.protected?(project, 'foo')).to eq(true)
+ expect(described_class.protected?(project, 'bar')).to eq(false)
+
+ create(:protected_tag, project: project, name: 'bar')
+
+ expect(described_class.protected?(project, 'bar')).to eq(true)
+ end
+
+ it 'correctly uses the cached version' do
+ expect(project).to receive(:protected_tags).once.and_call_original
+
+ 2.times do
+ expect(described_class.protected?(project, protected_tag.name)).to eq(true)
+ end
+ end
+ end
+ end
end