From 59c9ff627603da03f6a7c330d57a2c765b3c24a3 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 15 Feb 2022 08:58:20 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-7-stable-ee --- spec/models/packages/package_spec.rb | 75 ++++++++++++++++++++++++++++++++++-- spec/models/project_spec.rb | 19 ++++++++- 2 files changed, 90 insertions(+), 4 deletions(-) (limited to 'spec/models') diff --git a/spec/models/packages/package_spec.rb b/spec/models/packages/package_spec.rb index 0cb92f81da2..52ed52de193 100644 --- a/spec/models/packages/package_spec.rb +++ b/spec/models/packages/package_spec.rb @@ -475,6 +475,15 @@ RSpec.describe Packages::Package, type: :model do end end + shared_examples 'validating both if the first package is pending destruction' do + before do + package.status = :pending_destruction + end + + it_behaves_like 'validating the first package' + it_behaves_like 'validating the second package' + end + context 'following the naming convention' do let(:name) { "@#{group.path}/test" } @@ -503,6 +512,7 @@ RSpec.describe Packages::Package, type: :model do it_behaves_like 'validating the first package' it_behaves_like 'not validating the second package', field_with_error: :name + it_behaves_like 'validating both if the first package is pending destruction' end end @@ -531,6 +541,7 @@ RSpec.describe Packages::Package, type: :model do it_behaves_like 'validating the first package' it_behaves_like 'not validating the second package', field_with_error: :base + it_behaves_like 'validating both if the first package is pending destruction' end end end @@ -563,6 +574,7 @@ RSpec.describe Packages::Package, type: :model do it_behaves_like 'validating the first package' it_behaves_like 'not validating the second package', field_with_error: :name + it_behaves_like 'validating both if the first package is pending destruction' end end @@ -591,6 +603,7 @@ RSpec.describe Packages::Package, type: :model do it_behaves_like 'validating the first package' it_behaves_like 'validating the second package' + it_behaves_like 'validating both if the first package is pending destruction' end end end @@ -598,19 +611,53 @@ RSpec.describe Packages::Package, type: :model do end context "recipe uniqueness for conan packages" do - let!(:package) { create('conan_package') } + let_it_be(:package) { create(:conan_package) } it "will allow a conan package with same project, name, version and package_type" do - new_package = build('conan_package', project: package.project, name: package.name, version: package.version) + new_package = build(:conan_package, project: package.project, name: package.name, version: package.version) new_package.conan_metadatum.package_channel = 'beta' expect(new_package).to be_valid end it "will not allow a conan package with same recipe (name, version, metadatum.package_channel, metadatum.package_username, and package_type)" do - new_package = build('conan_package', project: package.project, name: package.name, version: package.version) + new_package = build(:conan_package, project: package.project, name: package.name, version: package.version) expect(new_package).not_to be_valid expect(new_package.errors.to_a).to include("Package recipe already exists") end + + context 'with pending destruction package' do + let_it_be(:package) { create(:conan_package, :pending_destruction) } + + it 'will allow a conan package with same recipe (name, version, metadatum.package_channel, metadatum.package_username, and package_type)' do + new_package = build(:conan_package, project: package.project, name: package.name, version: package.version) + expect(new_package).to be_valid + end + end + end + + describe '#valid_composer_global_name' do + let_it_be(:package) { create(:composer_package) } + + context 'with different name and different project' do + let(:new_package) { build(:composer_package, name: 'different_name') } + + it { expect(new_package).to be_valid } + end + + context 'with same name and different project' do + let(:new_package) { build(:composer_package, name: package.name) } + + it 'will not validate second package' do + expect(new_package).not_to be_valid + expect(new_package.errors.to_a).to include('Name is already taken by another project') + end + + context 'with pending destruction package' do + let_it_be(:package) { create(:composer_package, :pending_destruction) } + + it { expect(new_package).to be_valid } + end + end end describe "#unique_debian_package_name" do @@ -632,6 +679,16 @@ RSpec.describe Packages::Package, type: :model 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 + + context 'with pending_destruction package' do + let!(:package) { create(:debian_package, :pending_destruction) } + + it "will 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).to be_valid + end + end end Packages::Package.package_types.keys.without('conan', 'debian').each do |pt| @@ -1267,4 +1324,16 @@ RSpec.describe Packages::Package, type: :model do end end end + + context 'with identical pending destruction package' do + described_class.package_types.keys.each do |package_format| + context "for package format #{package_format}" do + let_it_be(:package_pending_destruction) { create("#{package_format}_package", :pending_destruction) } + + let(:new_package) { build("#{package_format}_package", name: package_pending_destruction.name, version: package_pending_destruction.version, project: package_pending_destruction.project) } + + it { expect(new_package).to be_valid } + end + end + end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 2fe50f8c48a..30114d36a06 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -7119,7 +7119,7 @@ RSpec.describe Project, factory_default: :keep do describe '#package_already_taken?' do let_it_be(:namespace) { create(:namespace, path: 'test') } let_it_be(:project) { create(:project, :public, namespace: namespace) } - let_it_be(:package) { create(:npm_package, project: project, name: "@#{namespace.path}/foo", version: '1.2.3') } + let_it_be_with_reload(:package) { create(:npm_package, project: project, name: "@#{namespace.path}/foo", version: '1.2.3') } subject { project.package_already_taken?(package_name, package_version, package_type: :npm) } @@ -7158,6 +7158,23 @@ RSpec.describe Project, factory_default: :keep do expect(result).to be false end end + + context 'with a pending_destruction package' do + before do + package.pending_destruction! + end + + where(:package_name, :package_version, :expected_result) do + '@test/bar' | '1.2.3' | false + '@test/bar' | '5.5.5' | false + '@test/foo' | '1.2.3' | false + '@test/foo' | '5.5.5' | false + end + + with_them do + it { is_expected.to eq expected_result} + end + end end end -- cgit v1.2.3