debian-mirror-gitlab/spec/models/packages/debian/file_metadatum_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

104 lines
3.4 KiB
Ruby
Raw Permalink Normal View History

2021-03-08 18:12:59 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-06-20 00:43:36 +05:30
RSpec.describe Packages::Debian::FileMetadatum, type: :model, feature_category: :package_registry do
RSpec.shared_context 'with Debian file metadatum' do |package_file_trait|
let_it_be_with_reload(:debian_package_file) { create(:debian_package_file, package_file_trait) }
2021-03-08 18:12:59 +05:30
let(:debian_file_metadatum) { debian_package_file.debian_file_metadatum }
subject { debian_file_metadatum }
end
2023-06-20 00:43:36 +05:30
RSpec.shared_examples 'Test Debian file metadatum' do |has_component, has_architecture, has_fields|
2021-03-08 18:12:59 +05:30
describe 'relationships' do
it { is_expected.to belong_to(:package_file) }
end
describe 'validations' do
describe '#package_file' do
it { is_expected.to validate_presence_of(:package_file) }
end
describe '#file_type' do
it { is_expected.to validate_presence_of(:file_type) }
end
describe '#component' do
it "has_component=#{has_component}" do
if has_component
is_expected.to validate_presence_of(:component)
is_expected.to allow_value('main').for(:component)
is_expected.not_to allow_value('hé').for(:component)
else
is_expected.to validate_absence_of(:component)
end
end
end
describe '#architecture' do
it "has_architecture=#{has_architecture}" do
if has_architecture
is_expected.to validate_presence_of(:architecture)
is_expected.to allow_value('amd64').for(:architecture)
is_expected.not_to allow_value('-a').for(:architecture)
else
is_expected.to validate_absence_of(:architecture)
end
end
end
describe '#fields' do
if has_fields
it { is_expected.to validate_presence_of(:fields) }
2023-06-20 00:43:36 +05:30
it { is_expected.to allow_value({ a: 'b' }).for(:fields) }
it { is_expected.not_to allow_value({ a: { b: 'c' } }).for(:fields) }
2021-03-08 18:12:59 +05:30
else
it { is_expected.to validate_absence_of(:fields) }
end
end
describe '#debian_package_type' do
before do
debian_package_file.package.package_type = :pypi
end
it 'validates package of type debian' do
expect(debian_file_metadatum).not_to be_valid
expect(debian_file_metadatum.errors.to_a).to contain_exactly('Package file Package type must be Debian')
end
end
end
2023-06-20 00:43:36 +05:30
describe 'scopes' do
describe '.with_file_type' do
subject { described_class.with_file_type(package_file_trait) }
it 'returns the matching file metadatum' do
expect(subject).to match_array([debian_file_metadatum])
end
end
end
2021-03-08 18:12:59 +05:30
end
using RSpec::Parameterized::TableSyntax
2023-06-20 00:43:36 +05:30
where(:package_file_trait, :has_component, :has_architecture, :has_fields) do
:unknown | false | false | false
:source | true | false | false
:dsc | true | false | true
:deb | true | true | true
:udeb | true | true | true
:ddeb | true | true | true
:buildinfo | true | false | true
:changes | false | false | true
2021-03-08 18:12:59 +05:30
end
with_them do
2023-06-20 00:43:36 +05:30
include_context 'with Debian file metadatum', params[:package_file_trait] do
it_behaves_like 'Test Debian file metadatum',
params[:has_component], params[:has_architecture], params[:has_fields]
2021-03-08 18:12:59 +05:30
end
end
end