Commit 3b143c7a authored by Shinya Maeda's avatar Shinya Maeda

Merge branch '334551-nuget-symbol-bug' into 'master'

Fix NuGet installs with symbol packages

See merge request gitlab-org/gitlab!64803
parents e374783c 246b31a9
......@@ -32,6 +32,7 @@ class Packages::PackageFile < ApplicationRecord
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_files_stored_locally, -> { where(file_store: ::Packages::PackageFileUploader::Store::LOCAL) }
scope :with_format, ->(format) { where(::Packages::PackageFile.arel_table[:file_name].matches("%.#{format}")) }
scope :preload_conan_file_metadata, -> { preload(:conan_file_metadatum) }
scope :preload_debian_file_metadata, -> { preload(:debian_file_metadatum) }
scope :preload_helm_file_metadata, -> { preload(:helm_file_metadatum) }
......
......@@ -8,6 +8,7 @@ module Packages
BLANK_STRING = ''
PACKAGE_DEPENDENCY_GROUP = 'PackageDependencyGroup'
PACKAGE_DEPENDENCY = 'PackageDependency'
NUGET_PACKAGE_FORMAT = 'nupkg'
private
......@@ -31,7 +32,7 @@ module Packages
id: package.project_id,
package_name: package.name,
package_version: package.version,
package_filename: package.package_files.last&.file_name
package_filename: package.package_files.with_format(NUGET_PACKAGE_FORMAT).last&.file_name
},
true
)
......
......@@ -5,6 +5,7 @@ RSpec.describe Packages::PackageFile, type: :model do
let_it_be(:project) { create(:project) }
let_it_be(:package_file1) { create(:package_file, :xml, file_name: 'FooBar') }
let_it_be(:package_file2) { create(:package_file, :xml, file_name: 'ThisIsATest') }
let_it_be(:package_file3) { create(:package_file, :xml, file_name: 'formatted.zip') }
let_it_be(:debian_package) { create(:debian_package, project: project) }
describe 'relationships' do
......@@ -36,6 +37,12 @@ RSpec.describe Packages::PackageFile, type: :model do
it { is_expected.to match_array([package_file1]) }
end
describe '.with_format' do
subject { described_class.with_format('zip') }
it { is_expected.to contain_exactly(package_file3) }
end
end
context 'updating project statistics' do
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Packages::Nuget::PackageMetadataPresenter do
include_context 'with expected presenters dependency groups'
let_it_be(:package) { create(:nuget_package, :with_metadatum) }
let_it_be(:package) { create(:nuget_package, :with_symbol_package, :with_metadatum) }
let_it_be(:tag1) { create(:packages_tag, name: 'tag1', package: package) }
let_it_be(:tag2) { create(:packages_tag, name: 'tag2', package: package) }
let_it_be(:presenter) { described_class.new(package) }
......@@ -19,7 +19,7 @@ RSpec.describe Packages::Nuget::PackageMetadataPresenter do
end
describe '#archive_url' do
let_it_be(:expected_suffix) { "/api/v4/projects/#{package.project_id}/packages/nuget/download/#{package.name}/#{package.version}/#{package.package_files.last.file_name}" }
let_it_be(:expected_suffix) { "/api/v4/projects/#{package.project_id}/packages/nuget/download/#{package.name}/#{package.version}/#{package.package_files.with_format('nupkg').last.file_name}" }
subject { presenter.archive_url }
......
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