diff options
Diffstat (limited to 'spec/models/packages')
7 files changed, 144 insertions, 0 deletions
diff --git a/spec/models/packages/debian/file_metadatum_spec.rb b/spec/models/packages/debian/file_metadatum_spec.rb new file mode 100644 index 00000000000..1215adfa6a1 --- /dev/null +++ b/spec/models/packages/debian/file_metadatum_spec.rb @@ -0,0 +1,91 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Debian::FileMetadatum, type: :model do + RSpec.shared_context 'Debian file metadatum' do |factory, trait| + let_it_be_with_reload(:debian_package_file) { create(factory, trait) } + let(:debian_file_metadatum) { debian_package_file.debian_file_metadatum } + + subject { debian_file_metadatum } + end + + RSpec.shared_examples 'Test Debian file metadatum' do |has_component, has_architecture, has_fields, has_outdated| + 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) } + it { is_expected.to allow_value({ 'a': 'b' }).for(:fields) } + it { is_expected.not_to allow_value({ 'a': { 'b': 'c' } }).for(:fields) } + 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 + end + + using RSpec::Parameterized::TableSyntax + + where(:factory, :trait, :has_component, :has_architecture, :has_fields) do + :debian_package_file | :unknown | false | false | false + :debian_package_file | :source | true | false | false + :debian_package_file | :dsc | true | false | true + :debian_package_file | :deb | true | true | true + :debian_package_file | :udeb | true | true | true + :debian_package_file | :buildinfo | true | false | true + :debian_package_file | :changes | false | false | true + end + + with_them do + include_context 'Debian file metadatum', params[:factory], params[:trait] do + it_behaves_like 'Test Debian file metadatum', params[:has_component], params[:has_architecture], params[:has_fields], params[:has_outdated] + end + end +end diff --git a/spec/models/packages/debian/group_architecture_spec.rb b/spec/models/packages/debian/group_architecture_spec.rb new file mode 100644 index 00000000000..a6def6e56cd --- /dev/null +++ b/spec/models/packages/debian/group_architecture_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Debian::GroupArchitecture do + it_behaves_like 'Debian Distribution Architecture', :debian_group_architecture, :group, false +end diff --git a/spec/models/packages/debian/group_distribution_spec.rb b/spec/models/packages/debian/group_distribution_spec.rb new file mode 100644 index 00000000000..90fb0d0e7d8 --- /dev/null +++ b/spec/models/packages/debian/group_distribution_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Debian::GroupDistribution do + it_behaves_like 'Debian Distribution', :debian_group_distribution, :group, false +end diff --git a/spec/models/packages/debian/project_architecture_spec.rb b/spec/models/packages/debian/project_architecture_spec.rb new file mode 100644 index 00000000000..b82ecabc4d4 --- /dev/null +++ b/spec/models/packages/debian/project_architecture_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Debian::ProjectArchitecture do + it_behaves_like 'Debian Distribution Architecture', :debian_project_architecture, :project, true +end diff --git a/spec/models/packages/debian/project_distribution_spec.rb b/spec/models/packages/debian/project_distribution_spec.rb new file mode 100644 index 00000000000..5f4041ad9fe --- /dev/null +++ b/spec/models/packages/debian/project_distribution_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Debian::ProjectDistribution do + it_behaves_like 'Debian Distribution', :debian_project_distribution, :project, true +end diff --git a/spec/models/packages/package_file_spec.rb b/spec/models/packages/package_file_spec.rb index 82ac159b9cc..ebb10e991ad 100644 --- a/spec/models/packages/package_file_spec.rb +++ b/spec/models/packages/package_file_spec.rb @@ -7,6 +7,7 @@ RSpec.describe Packages::PackageFile, type: :model do it { is_expected.to have_one(:conan_file_metadatum) } it { is_expected.to have_many(:package_file_build_infos).inverse_of(:package_file) } it { is_expected.to have_many(:pipelines).through(:package_file_build_infos) } + it { is_expected.to have_one(:debian_file_metadatum).inverse_of(:package_file).class_name('Packages::Debian::FileMetadatum') } end describe 'validations' do diff --git a/spec/models/packages/package_spec.rb b/spec/models/packages/package_spec.rb index 16764673474..6645db33503 100644 --- a/spec/models/packages/package_spec.rb +++ b/spec/models/packages/package_spec.rb @@ -599,6 +599,20 @@ RSpec.describe Packages::Package, type: :model do end end + describe '.order_by_package_file' do + let_it_be(:project) { create(:project) } + let_it_be(:package1) { create(:maven_package, project: project) } + let_it_be(:package2) { create(:maven_package, project: project) } + + it 'orders packages their associated package_file\'s created_at date', :aggregate_failures do + expect(project.packages.order_by_package_file).to match_array([package1, package1, package1, package2, package2, package2]) + + create(:package_file, :xml, package: package1) + + expect(project.packages.order_by_package_file).to match_array([package1, package1, package1, package2, package2, package2, package1]) + end + end + describe '#versions' do let_it_be(:project) { create(:project) } let_it_be(:package) { create(:maven_package, project: project) } @@ -731,4 +745,14 @@ RSpec.describe Packages::Package, type: :model do end end end + + describe '#package_settings' do + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } + let_it_be(:package) { create(:maven_package, project: project) } + + it 'returns the namespace package_settings' do + expect(package.package_settings).to eq(group.package_settings) + end + end end |