2020-12-02 01:09:50 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe DependencyProxy::Manifest, type: :model do
|
2021-09-29 14:12:42 -04:00
|
|
|
it_behaves_like 'ttl_expirable'
|
2022-01-18 10:14:54 -05:00
|
|
|
it_behaves_like 'destructible', factory: :dependency_proxy_manifest
|
2021-09-29 14:12:42 -04:00
|
|
|
|
2020-12-02 01:09:50 -05:00
|
|
|
describe 'relationships' do
|
|
|
|
it { is_expected.to belong_to(:group) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:group) }
|
|
|
|
it { is_expected.to validate_presence_of(:file) }
|
|
|
|
it { is_expected.to validate_presence_of(:file_name) }
|
|
|
|
it { is_expected.to validate_presence_of(:digest) }
|
|
|
|
end
|
|
|
|
|
2021-11-09 10:12:42 -05:00
|
|
|
describe 'scopes' do
|
|
|
|
let_it_be(:manifest_one) { create(:dependency_proxy_manifest) }
|
|
|
|
let_it_be(:manifest_two) { create(:dependency_proxy_manifest) }
|
|
|
|
let_it_be(:manifests) { [manifest_one, manifest_two] }
|
|
|
|
let_it_be(:ids) { manifests.map(&:id) }
|
|
|
|
|
|
|
|
it 'order_id_desc' do
|
|
|
|
expect(described_class.where(id: ids).order_id_desc.to_a).to eq [manifest_two, manifest_one]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-02 01:09:50 -05:00
|
|
|
describe 'file is being stored' do
|
|
|
|
subject { create(:dependency_proxy_manifest) }
|
|
|
|
|
|
|
|
context 'when existing object has local store' do
|
|
|
|
it_behaves_like 'mounted file in local store'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when direct upload is enabled' do
|
|
|
|
before do
|
|
|
|
stub_dependency_proxy_object_storage(direct_upload: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'mounted file in object store'
|
|
|
|
end
|
|
|
|
end
|
2020-12-10 19:09:41 -05:00
|
|
|
|
2021-11-04 05:12:56 -04:00
|
|
|
describe '.find_by_file_name_or_digest' do
|
2021-02-22 13:10:55 -05:00
|
|
|
let_it_be(:file_name) { 'foo' }
|
|
|
|
let_it_be(:digest) { 'bar' }
|
2020-12-10 19:09:41 -05:00
|
|
|
|
2021-11-04 05:12:56 -04:00
|
|
|
subject { DependencyProxy::Manifest.find_by_file_name_or_digest(file_name: file_name, digest: digest) }
|
2021-02-08 04:09:30 -05:00
|
|
|
|
2021-02-22 13:10:55 -05:00
|
|
|
context 'no manifest exists' do
|
2021-11-04 05:12:56 -04:00
|
|
|
it { is_expected.to be_nil }
|
2020-12-10 19:09:41 -05:00
|
|
|
end
|
|
|
|
|
2021-02-22 13:10:55 -05:00
|
|
|
context 'manifest exists and matches file_name' do
|
2020-12-10 19:09:41 -05:00
|
|
|
let_it_be(:dependency_proxy_manifest) { create(:dependency_proxy_manifest) }
|
|
|
|
let_it_be(:file_name) { dependency_proxy_manifest.file_name }
|
|
|
|
|
|
|
|
it { is_expected.to eq(dependency_proxy_manifest) }
|
|
|
|
end
|
2021-02-22 13:10:55 -05:00
|
|
|
|
|
|
|
context 'manifest exists and matches digest' do
|
|
|
|
let_it_be(:dependency_proxy_manifest) { create(:dependency_proxy_manifest) }
|
|
|
|
let_it_be(:digest) { dependency_proxy_manifest.digest }
|
|
|
|
|
|
|
|
it { is_expected.to eq(dependency_proxy_manifest) }
|
|
|
|
end
|
2020-12-10 19:09:41 -05:00
|
|
|
end
|
2020-12-02 01:09:50 -05:00
|
|
|
end
|