Commit a31e72db authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '225860-fix-packages-scope-in-conan-package-presenter' into 'master'

The conan package presenter will now only read conan packages

See merge request gitlab-org/gitlab!35971
parents 8669a344 0cbb2f1c
...@@ -20,7 +20,7 @@ class Packages::PackageFile < ApplicationRecord ...@@ -20,7 +20,7 @@ class Packages::PackageFile < ApplicationRecord
scope :with_file_name, ->(file_name) { where(file_name: file_name) } scope :with_file_name, ->(file_name) { where(file_name: file_name) }
scope :with_file_name_like, ->(file_name) { where(arel_table[:file_name].matches(file_name)) } scope :with_file_name_like, ->(file_name) { where(arel_table[:file_name].matches(file_name)) }
scope :with_files_stored_locally, -> { where(file_store: ::Packages::PackageFileUploader::Store::LOCAL) } scope :with_files_stored_locally, -> { where(file_store: ::Packages::PackageFileUploader::Store::LOCAL) }
scope :with_conan_file_metadata, -> { includes(:conan_file_metadatum) } scope :preload_conan_file_metadata, -> { preload(:conan_file_metadatum) }
scope :with_conan_file_type, ->(file_type) do scope :with_conan_file_type, ->(file_type) do
joins(:conan_file_metadatum) joins(:conan_file_metadatum)
......
...@@ -86,14 +86,19 @@ module Packages ...@@ -86,14 +86,19 @@ module Packages
def package_files def package_files
return unless package return unless package
@package_files ||= package.package_files.with_conan_file_metadata @package_files ||= package.package_files.preload_conan_file_metadata
end end
def package def package
strong_memoize(:package) do strong_memoize(:package) do
name, version = @recipe.split('@')[0].split('/') name, version = @recipe.split('@')[0].split('/')
@project.packages.with_name(name).with_version(version).order_created.last @project.packages
.conan
.with_name(name)
.with_version(version)
.order_created
.last
end end
end end
......
---
title: The conan package presenter will now only read conan packages
merge_request: 35971
author:
type: fixed
...@@ -7,6 +7,16 @@ RSpec.describe ::Packages::Conan::PackagePresenter do ...@@ -7,6 +7,16 @@ RSpec.describe ::Packages::Conan::PackagePresenter do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:conan_package_reference) { '123456789'} let_it_be(:conan_package_reference) { '123456789'}
RSpec.shared_examples 'not selecting a package with the wrong type' do
context 'with a nuget package with same name and version' do
let_it_be(:wrong_package) { create(:nuget_package, name: 'wrong', version: '1.0.0', project: project) }
let(:recipe) { "#{wrong_package.name}/#{wrong_package.version}" }
it { is_expected.to be_empty }
end
end
describe '#recipe_urls' do describe '#recipe_urls' do
subject { described_class.new(recipe, user, project).recipe_urls } subject { described_class.new(recipe, user, project).recipe_urls }
...@@ -16,6 +26,8 @@ RSpec.describe ::Packages::Conan::PackagePresenter do ...@@ -16,6 +26,8 @@ RSpec.describe ::Packages::Conan::PackagePresenter do
it { is_expected.to be_empty } it { is_expected.to be_empty }
end end
it_behaves_like 'not selecting a package with the wrong type'
context 'existing package' do context 'existing package' do
let(:package) { create(:conan_package, project: project) } let(:package) { create(:conan_package, project: project) }
let(:recipe) { package.conan_recipe } let(:recipe) { package.conan_recipe }
...@@ -40,6 +52,8 @@ RSpec.describe ::Packages::Conan::PackagePresenter do ...@@ -40,6 +52,8 @@ RSpec.describe ::Packages::Conan::PackagePresenter do
it { is_expected.to be_empty } it { is_expected.to be_empty }
end end
it_behaves_like 'not selecting a package with the wrong type'
context 'existing package' do context 'existing package' do
let(:package) { create(:conan_package, project: project) } let(:package) { create(:conan_package, project: project) }
let(:recipe) { package.conan_recipe } let(:recipe) { package.conan_recipe }
...@@ -70,6 +84,8 @@ RSpec.describe ::Packages::Conan::PackagePresenter do ...@@ -70,6 +84,8 @@ RSpec.describe ::Packages::Conan::PackagePresenter do
it { is_expected.to be_empty } it { is_expected.to be_empty }
end end
it_behaves_like 'not selecting a package with the wrong type'
context 'existing package' do context 'existing package' do
let(:package) { create(:conan_package, project: project) } let(:package) { create(:conan_package, project: project) }
let(:recipe) { package.conan_recipe } let(:recipe) { package.conan_recipe }
...@@ -139,6 +155,8 @@ RSpec.describe ::Packages::Conan::PackagePresenter do ...@@ -139,6 +155,8 @@ RSpec.describe ::Packages::Conan::PackagePresenter do
it { is_expected.to be_empty } it { is_expected.to be_empty }
end end
it_behaves_like 'not selecting a package with the wrong type'
context 'existing package' do context 'existing package' do
let(:package) { create(:conan_package, project: project) } let(:package) { create(:conan_package, project: project) }
let(:recipe) { package.conan_recipe } let(:recipe) { package.conan_recipe }
......
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