2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Packages::PackageFileFinder do
|
|
|
|
let_it_be(:package) { create(:maven_package) }
|
|
|
|
let_it_be(:package_file) { package.package_files.first }
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
let(:package_file_name) { package_file.file_name }
|
|
|
|
let(:params) { {} }
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
shared_examples 'package file finder examples' do
|
2020-07-28 23:09:34 +05:30
|
|
|
it { is_expected.to eq(package_file) }
|
|
|
|
|
|
|
|
context 'with file_name_like' do
|
|
|
|
let(:package_file_name) { package_file.file_name.upcase }
|
|
|
|
let(:params) { { with_file_name_like: true } }
|
|
|
|
|
|
|
|
it { is_expected.to eq(package_file) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
shared_examples 'not returning pending_destruction package files' do
|
|
|
|
let_it_be(:recent_package_file_pending_destruction) do
|
|
|
|
create(:package_file, :pending_destruction, package: package, file_name: package_file.file_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the correct package file' do
|
|
|
|
expect(package.package_files.last).to eq(recent_package_file_pending_destruction)
|
|
|
|
|
|
|
|
expect(subject).to eq(package_file)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with packages_installable_package_files disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(packages_installable_package_files: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns them' do
|
|
|
|
expect(subject).to eq(recent_package_file_pending_destruction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
describe '#execute' do
|
|
|
|
subject { described_class.new(package, package_file_name, params).execute }
|
|
|
|
|
|
|
|
it_behaves_like 'package file finder examples'
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it_behaves_like 'not returning pending_destruction package files'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
context 'with unknown file_name' do
|
|
|
|
let(:package_file_name) { 'unknown.jpg' }
|
|
|
|
|
|
|
|
it { expect(subject).to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute!' do
|
|
|
|
subject { described_class.new(package, package_file_name, params).execute! }
|
|
|
|
|
|
|
|
it_behaves_like 'package file finder examples'
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it_behaves_like 'not returning pending_destruction package files'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
context 'with unknown file_name' do
|
|
|
|
let(:package_file_name) { 'unknown.jpg' }
|
|
|
|
|
|
|
|
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|