diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/finders/packages/maven | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/finders/packages/maven')
-rw-r--r-- | spec/finders/packages/maven/package_finder_spec.rb | 80 |
1 files changed, 52 insertions, 28 deletions
diff --git a/spec/finders/packages/maven/package_finder_spec.rb b/spec/finders/packages/maven/package_finder_spec.rb index 239e8c10f52..b955c331f28 100644 --- a/spec/finders/packages/maven/package_finder_spec.rb +++ b/spec/finders/packages/maven/package_finder_spec.rb @@ -1,57 +1,81 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe ::Packages::Maven::PackageFinder do - let(:user) { create(:user) } - let(:group) { create(:group) } - let(:project) { create(:project, namespace: group) } - let(:package) { create(:maven_package, project: project) } + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, namespace: group) } + let_it_be(:package) { create(:maven_package, project: project) } + + let(:param_path) { nil } + let(:param_project) { nil } + let(:param_group) { nil } + let(:finder) { described_class.new(param_path, user, project: param_project, group: param_group) } before do group.add_developer(user) end describe '#execute!' do - context 'within the project' do - it 'returns a package' do - finder = described_class.new(package.maven_metadatum.path, user, project: project) - - expect(finder.execute!).to eq(package) - end + subject { finder.execute! } - it 'raises an error' do - finder = described_class.new('com/example/my-app/1.0-SNAPSHOT', user, project: project) + shared_examples 'handling valid and invalid paths' do + context 'with a valid path' do + let(:param_path) { package.maven_metadatum.path } - expect { finder.execute! }.to raise_error(ActiveRecord::RecordNotFound) + it { is_expected.to eq(package) } end - end - context 'across all projects' do - it 'returns a package' do - finder = described_class.new(package.maven_metadatum.path, user) + context 'with an invalid path' do + let(:param_path) { 'com/example/my-app/1.0-SNAPSHOT' } - expect(finder.execute!).to eq(package) + it 'raises an error' do + expect { subject }.to raise_error(ActiveRecord::RecordNotFound) + end end + end - it 'raises an error' do - finder = described_class.new('com/example/my-app/1.0-SNAPSHOT', user) + context 'within the project' do + let(:param_project) { project } - expect { finder.execute! }.to raise_error(ActiveRecord::RecordNotFound) - end + it_behaves_like 'handling valid and invalid paths' end context 'within a group' do - it 'returns a package' do - finder = described_class.new(package.maven_metadatum.path, user, group: group) + let(:param_group) { group } - expect(finder.execute!).to eq(package) - end + it_behaves_like 'handling valid and invalid paths' + end + context 'across all projects' do it 'raises an error' do - finder = described_class.new('com/example/my-app/1.0-SNAPSHOT', user, group: group) + expect { subject }.to raise_error(ActiveRecord::RecordNotFound) + end + end + + context 'versionless maven-metadata.xml package' do + let_it_be(:sub_group1) { create(:group, parent: group) } + let_it_be(:sub_group2) { create(:group, parent: group) } + let_it_be(:project1) { create(:project, group: sub_group1) } + let_it_be(:project2) { create(:project, group: sub_group2) } + let_it_be(:project3) { create(:project, group: sub_group1) } + let_it_be(:package_name) { 'foo' } + let_it_be(:package1) { create(:maven_package, project: project1, name: package_name, version: nil) } + let_it_be(:package2) { create(:maven_package, project: project2, name: package_name, version: nil) } + let_it_be(:package3) { create(:maven_package, project: project3, name: package_name, version: nil) } - expect { finder.execute! }.to raise_error(ActiveRecord::RecordNotFound) + let(:param_group) { group } + let(:param_path) { package_name } + + before do + sub_group1.add_developer(user) + sub_group2.add_developer(user) + # the package with the most recently published file should be returned + create(:package_file, :xml, package: package2) end + + it { is_expected.to eq(package2) } end end end |