Commit f9690ffb authored by David Fernandez's avatar David Fernandez Committed by Markus Koller

Update the maven package finder

A group or project is now required for the finder to return packages
parent f006fea3
......@@ -27,7 +27,7 @@ module Packages
elsif group
packages_for_multiple_projects
else
packages
::Packages::Package.none
end
end
......@@ -35,11 +35,6 @@ module Packages
base.only_maven_packages_with_path(path)
end
# Produces a query that returns all packages.
def packages
::Packages::Package.all
end
# Produces a query that retrieves packages from a single project.
def packages_for_a_single_project
project.packages
......
---
title: Update the maven package finder
merge_request: 50774
author:
type: changed
......@@ -2,55 +2,54 @@
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)
subject { finder.execute! }
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
it 'raises an error' do
finder = described_class.new('com/example/my-app/1.0-SNAPSHOT', user, project: project)
context 'with an invalid path' do
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
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
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)
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 { finder.execute! }.to raise_error(ActiveRecord::RecordNotFound)
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
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