diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/models/packages | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) | |
download | gitlab-ce-859a6fb938bb9ee2a317c46dfa4fcc1af49608f0.tar.gz |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/models/packages')
-rw-r--r-- | spec/models/packages/composer/cache_file_spec.rb | 32 | ||||
-rw-r--r-- | spec/models/packages/composer/metadatum_spec.rb | 16 | ||||
-rw-r--r-- | spec/models/packages/debian/group_component_file_spec.rb | 7 | ||||
-rw-r--r-- | spec/models/packages/debian/group_component_spec.rb | 7 | ||||
-rw-r--r-- | spec/models/packages/debian/project_component_file_spec.rb | 7 | ||||
-rw-r--r-- | spec/models/packages/debian/project_component_spec.rb | 7 | ||||
-rw-r--r-- | spec/models/packages/debian/publication_spec.rb | 47 | ||||
-rw-r--r-- | spec/models/packages/package_spec.rb | 50 | ||||
-rw-r--r-- | spec/models/packages/rubygems/metadatum_spec.rb | 22 |
9 files changed, 194 insertions, 1 deletions
diff --git a/spec/models/packages/composer/cache_file_spec.rb b/spec/models/packages/composer/cache_file_spec.rb new file mode 100644 index 00000000000..a03b89ca2f5 --- /dev/null +++ b/spec/models/packages/composer/cache_file_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Packages::Composer::CacheFile, type: :model do + describe 'relationships' do + it { is_expected.to belong_to(:group) } + it { is_expected.to belong_to(:namespace) } + end + + describe 'validations' do + it { is_expected.to validate_presence_of(:namespace) } + end + + describe 'scopes' do + let_it_be(:group1) { create(:group) } + let_it_be(:group2) { create(:group) } + let_it_be(:cache_file1) { create(:composer_cache_file, file_sha256: '123456', group: group1) } + let_it_be(:cache_file2) { create(:composer_cache_file, delete_at: 2.days.from_now, file_sha256: '456778', group: group2) } + + describe '.with_namespace' do + subject { described_class.with_namespace(group1) } + + it { is_expected.to eq [cache_file1] } + end + + describe '.with_sha' do + subject { described_class.with_sha('123456') } + + it { is_expected.to eq [cache_file1] } + end + end +end diff --git a/spec/models/packages/composer/metadatum_spec.rb b/spec/models/packages/composer/metadatum_spec.rb index ae53532696b..1c888f1563c 100644 --- a/spec/models/packages/composer/metadatum_spec.rb +++ b/spec/models/packages/composer/metadatum_spec.rb @@ -11,4 +11,20 @@ RSpec.describe Packages::Composer::Metadatum, type: :model do it { is_expected.to validate_presence_of(:target_sha) } it { is_expected.to validate_presence_of(:composer_json) } end + + describe 'scopes' do + let_it_be(:package_name) { 'sample-project' } + let_it_be(:json) { { 'name' => package_name } } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, :custom_repo, files: { 'composer.json' => json.to_json }, group: group) } + let_it_be(:package1) { create(:composer_package, :with_metadatum, project: project, name: package_name, version: '1.0.0', json: json) } + let_it_be(:package2) { create(:composer_package, :with_metadatum, project: project, name: 'other-name', version: '1.0.0', json: json) } + let_it_be(:package3) { create(:pypi_package, name: package_name, project: project) } + + describe '.for_package' do + subject { described_class.for_package(package_name, project.id) } + + it { is_expected.to eq [package1.composer_metadatum] } + end + end end diff --git a/spec/models/packages/debian/group_component_file_spec.rb b/spec/models/packages/debian/group_component_file_spec.rb new file mode 100644 index 00000000000..bf33ca138c3 --- /dev/null +++ b/spec/models/packages/debian/group_component_file_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Debian::GroupComponentFile do + it_behaves_like 'Debian Component File', :group, false +end diff --git a/spec/models/packages/debian/group_component_spec.rb b/spec/models/packages/debian/group_component_spec.rb new file mode 100644 index 00000000000..f288ebbe5df --- /dev/null +++ b/spec/models/packages/debian/group_component_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Debian::GroupComponent do + it_behaves_like 'Debian Distribution Component', :debian_group_component, :group, false +end diff --git a/spec/models/packages/debian/project_component_file_spec.rb b/spec/models/packages/debian/project_component_file_spec.rb new file mode 100644 index 00000000000..5dfc47c14c0 --- /dev/null +++ b/spec/models/packages/debian/project_component_file_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Debian::ProjectComponentFile do + it_behaves_like 'Debian Component File', :project, true +end diff --git a/spec/models/packages/debian/project_component_spec.rb b/spec/models/packages/debian/project_component_spec.rb new file mode 100644 index 00000000000..4b041068b8d --- /dev/null +++ b/spec/models/packages/debian/project_component_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Debian::ProjectComponent do + it_behaves_like 'Debian Distribution Component', :debian_project_component, :project, true +end diff --git a/spec/models/packages/debian/publication_spec.rb b/spec/models/packages/debian/publication_spec.rb new file mode 100644 index 00000000000..0ed056f499b --- /dev/null +++ b/spec/models/packages/debian/publication_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Packages::Debian::Publication, type: :model do + let_it_be_with_reload(:publication) { create(:debian_publication) } + + subject { publication } + + describe 'relationships' do + it { is_expected.to belong_to(:package).inverse_of(:debian_publication).class_name('Packages::Package') } + it { is_expected.to belong_to(:distribution).inverse_of(:publications).class_name('Packages::Debian::ProjectDistribution').with_foreign_key(:distribution_id) } + end + + describe 'validations' do + describe '#package' do + it { is_expected.to validate_presence_of(:package) } + end + + describe '#valid_debian_package_type' do + context 'with package type not being Debian' do + before do + publication.package.package_type = 'generic' + end + + it 'will not allow package type not being Debian' do + expect(publication).not_to be_valid + expect(publication.errors.to_a).to eq(['Package type must be Debian']) + end + end + + context 'with package not being a Debian package' do + before do + publication.package.version = nil + end + + it 'will not allow package not being a distribution' do + expect(publication).not_to be_valid + expect(publication.errors.to_a).to eq(['Package must be a Debian package']) + end + end + end + + describe '#distribution' do + it { is_expected.to validate_presence_of(:distribution) } + end + end +end diff --git a/spec/models/packages/package_spec.rb b/spec/models/packages/package_spec.rb index 6645db33503..6c55d37b95f 100644 --- a/spec/models/packages/package_spec.rb +++ b/spec/models/packages/package_spec.rb @@ -4,6 +4,8 @@ require 'spec_helper' RSpec.describe Packages::Package, type: :model do include SortingHelper + it_behaves_like 'having unique enum values' + describe 'relationships' do it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:creator) } @@ -14,7 +16,10 @@ RSpec.describe Packages::Package, type: :model do it { is_expected.to have_many(:pipelines).through(:build_infos) } it { is_expected.to have_one(:conan_metadatum).inverse_of(:package) } it { is_expected.to have_one(:maven_metadatum).inverse_of(:package) } + it { is_expected.to have_one(:debian_publication).inverse_of(:package).class_name('Packages::Debian::Publication') } + it { is_expected.to have_one(:debian_distribution).through(:debian_publication).source(:distribution).inverse_of(:packages).class_name('Packages::Debian::ProjectDistribution') } it { is_expected.to have_one(:nuget_metadatum).inverse_of(:package) } + it { is_expected.to have_one(:rubygems_metadatum).inverse_of(:package) } end describe '.with_composer_target' do @@ -374,7 +379,28 @@ RSpec.describe Packages::Package, type: :model do end end - Packages::Package.package_types.keys.without('conan').each do |pt| + describe "#unique_debian_package_name" do + let!(:package) { create(:debian_package) } + + it "will allow a Debian package with same project, name and version, but different distribution" do + new_package = build(:debian_package, project: package.project, name: package.name, version: package.version) + expect(new_package).to be_valid + end + + it "will not allow a Debian package with same project, name, version and distribution" do + new_package = build(:debian_package, project: package.project, name: package.name, version: package.version) + new_package.debian_publication.distribution = package.debian_publication.distribution + expect(new_package).not_to be_valid + expect(new_package.errors.to_a).to include('Debian package already exists in Distribution') + end + + it "will allow a Debian package with same project, name, version, but no distribution" do + new_package = build(:debian_package, project: package.project, name: package.name, version: package.version, published_in: nil) + expect(new_package).to be_valid + end + end + + Packages::Package.package_types.keys.without('conan', 'debian').each do |pt| context "project id, name, version and package type uniqueness for package type #{pt}" do let(:package) { create("#{pt}_package") } @@ -581,6 +607,28 @@ RSpec.describe Packages::Package, type: :model do it { is_expected.to match_array([pypi_package]) } end + + describe '.displayable' do + let_it_be(:hidden_package) { create(:maven_package, :hidden) } + let_it_be(:processing_package) { create(:maven_package, :processing) } + + subject { described_class.displayable } + + it 'does not include hidden packages', :aggregate_failures do + is_expected.not_to include(hidden_package) + is_expected.not_to include(processing_package) + end + end + + describe '.with_status' do + let_it_be(:hidden_package) { create(:maven_package, :hidden) } + + subject { described_class.with_status(:hidden) } + + it 'returns packages with specified status' do + is_expected.to match_array([hidden_package]) + end + end end describe '.select_distinct_name' do diff --git a/spec/models/packages/rubygems/metadatum_spec.rb b/spec/models/packages/rubygems/metadatum_spec.rb new file mode 100644 index 00000000000..e99a07c7731 --- /dev/null +++ b/spec/models/packages/rubygems/metadatum_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Packages::Rubygems::Metadatum, type: :model do + describe 'relationships' do + it { is_expected.to belong_to(:package) } + end + + describe 'validations' do + it { is_expected.to validate_presence_of(:package) } + + describe '#rubygems_package_type' do + it 'will not allow a package with a different package_type' do + package = build('conan_package') + rubygems_metadatum = build('rubygems_metadatum', package: package) + + expect(rubygems_metadatum).not_to be_valid + expect(rubygems_metadatum.errors.to_a).to include('Package type must be RubyGems') + end + end + end +end |