diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
commit | 5afcbe03ead9ada87621888a31a62652b10a7e4f (patch) | |
tree | 9918b67a0d0f0bafa6542e839a8be37adf73102d /spec/models/packages/nuget/symbol_spec.rb | |
parent | c97c0201564848c1f53226fe19d71fdcc472f7d0 (diff) |
Add latest changes from gitlab-org/gitlab@16-4-stable-eev16.4.0-rc42
Diffstat (limited to 'spec/models/packages/nuget/symbol_spec.rb')
-rw-r--r-- | spec/models/packages/nuget/symbol_spec.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/models/packages/nuget/symbol_spec.rb b/spec/models/packages/nuget/symbol_spec.rb new file mode 100644 index 00000000000..52e95c11939 --- /dev/null +++ b/spec/models/packages/nuget/symbol_spec.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Nuget::Symbol, type: :model, feature_category: :package_registry do + subject(:symbol) { create(:nuget_symbol) } + + it { is_expected.to be_a FileStoreMounter } + + describe 'relationships' do + it { is_expected.to belong_to(:package).inverse_of(:nuget_symbols) } + end + + describe 'validations' do + it { is_expected.to validate_presence_of(:file) } + it { is_expected.to validate_presence_of(:file_path) } + it { is_expected.to validate_presence_of(:signature) } + it { is_expected.to validate_presence_of(:object_storage_key) } + it { is_expected.to validate_presence_of(:size) } + it { is_expected.to validate_uniqueness_of(:signature).scoped_to(:file_path) } + it { is_expected.to validate_uniqueness_of(:object_storage_key).case_insensitive } + end + + describe 'delegations' do + it { is_expected.to delegate_method(:project_id).to(:package) } + end + + describe 'callbacks' do + describe 'before_validation' do + describe '#set_object_storage_key' do + context 'when signature and project_id are present' do + it 'sets the object_storage_key' do + expected_key = Gitlab::HashedPath.new( + 'packages', 'nuget', symbol.package_id, 'symbols', OpenSSL::Digest::SHA256.hexdigest(symbol.signature), + root_hash: symbol.project_id + ).to_s + + symbol.valid? + + expect(symbol.object_storage_key).to eq(expected_key) + end + end + + context 'when signature is not present' do + subject(:symbol) { build(:nuget_symbol, signature: nil) } + + it 'does not set the object_storage_key' do + symbol.valid? + + expect(symbol.object_storage_key).to be_nil + end + end + + context 'when project_id is not present' do + subject(:symbol) { build(:nuget_symbol) } + + before do + allow(symbol).to receive(:project_id).and_return(nil) + end + + it 'does not set the object_storage_key' do + symbol.valid? + + expect(symbol.object_storage_key).to be_nil + end + end + end + end + end +end |