Commit a01d8a60 authored by Markus Koller's avatar Markus Koller

Merge branch '284686-fix-the-maven-packages-finder' into 'master'

Update the maven package finder

See merge request gitlab-org/gitlab!50774
parents 3c464edb f9690ffb
...@@ -27,7 +27,7 @@ module Packages ...@@ -27,7 +27,7 @@ module Packages
elsif group elsif group
packages_for_multiple_projects packages_for_multiple_projects
else else
packages ::Packages::Package.none
end end
end end
...@@ -35,11 +35,6 @@ module Packages ...@@ -35,11 +35,6 @@ module Packages
base.only_maven_packages_with_path(path) base.only_maven_packages_with_path(path)
end end
# Produces a query that returns all packages.
def packages
::Packages::Package.all
end
# Produces a query that retrieves packages from a single project. # Produces a query that retrieves packages from a single project.
def packages_for_a_single_project def packages_for_a_single_project
project.packages project.packages
......
---
title: Update the maven package finder
merge_request: 50774
author:
type: changed
...@@ -2,55 +2,54 @@ ...@@ -2,55 +2,54 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe ::Packages::Maven::PackageFinder do RSpec.describe ::Packages::Maven::PackageFinder do
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:group) { create(:group) } let_it_be(:group) { create(:group) }
let(:project) { create(:project, namespace: group) } let_it_be(:project) { create(:project, namespace: group) }
let(:package) { create(:maven_package, project: project) } 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 before do
group.add_developer(user) group.add_developer(user)
end end
describe '#execute!' do describe '#execute!' do
context 'within the project' do subject { finder.execute! }
it 'returns a package' do
finder = described_class.new(package.maven_metadatum.path, user, project: project)
expect(finder.execute!).to eq(package) shared_examples 'handling valid and invalid paths' do
context 'with a valid path' do
let(:param_path) { package.maven_metadatum.path }
it { is_expected.to eq(package) }
end end
it 'raises an error' do context 'with an invalid path' do
finder = described_class.new('com/example/my-app/1.0-SNAPSHOT', user, project: project) let(:param_path) { 'com/example/my-app/1.0-SNAPSHOT' }
expect { finder.execute! }.to raise_error(ActiveRecord::RecordNotFound) it 'raises an error' do
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
end end
end end
context 'across all projects' do
it 'returns a package' do
finder = described_class.new(package.maven_metadatum.path, user)
expect(finder.execute!).to eq(package)
end end
it 'raises an error' do context 'within the project' do
finder = described_class.new('com/example/my-app/1.0-SNAPSHOT', user) let(:param_project) { project }
expect { finder.execute! }.to raise_error(ActiveRecord::RecordNotFound) it_behaves_like 'handling valid and invalid paths'
end
end end
context 'within a group' do context 'within a group' do
it 'returns a package' do let(:param_group) { group }
finder = described_class.new(package.maven_metadatum.path, user, group: group)
expect(finder.execute!).to eq(package) it_behaves_like 'handling valid and invalid paths'
end end
context 'across all projects' do
it 'raises an error' 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)
expect { finder.execute! }.to raise_error(ActiveRecord::RecordNotFound)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment