Commit fd11e813 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '10io-fix-nuget-package-file-update-from-metadata' into 'master'

Fix nuget package file update

See merge request gitlab-org/gitlab!24064
parents ca00a138 680b9d98
...@@ -17,7 +17,10 @@ module Packages ...@@ -17,7 +17,10 @@ module Packages
raise InvalidMetadataError.new('package name and/or package version not found in metadata') unless valid_metadata? raise InvalidMetadataError.new('package name and/or package version not found in metadata') unless valid_metadata?
package_file.transaction do package_file.transaction do
package_file.update!(file_name: package_filename) if package_filename package_file.update!(
file_name: package_filename,
file: package_file.file
)
if existing_package_id if existing_package_id
link_to_existing_package link_to_existing_package
...@@ -74,8 +77,6 @@ module Packages ...@@ -74,8 +77,6 @@ module Packages
end end
def package_filename def package_filename
return unless package_name && package_version
"#{package_name.downcase}.#{package_version.downcase}.nupkg" "#{package_name.downcase}.#{package_version.downcase}.nupkg"
end end
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
describe Packages::Nuget::UpdatePackageFromMetadataService do describe Packages::Nuget::UpdatePackageFromMetadataService do
let!(:package) { create(:nuget_package) } let(:package) { create(:nuget_package) }
let(:package_file) { package.package_files.first } let(:package_file) { package.package_files.first }
let(:service) { described_class.new(package_file) } let(:service) { described_class.new(package_file) }
let(:package_name) { 'DummyProject.DummyPackage' } let(:package_name) { 'DummyProject.DummyPackage' }
...@@ -13,12 +13,18 @@ describe Packages::Nuget::UpdatePackageFromMetadataService do ...@@ -13,12 +13,18 @@ describe Packages::Nuget::UpdatePackageFromMetadataService do
describe '#execute' do describe '#execute' do
subject { service.execute } subject { service.execute }
before do
stub_package_file_object_storage(enabled: true, direct_upload: true)
end
it 'updates package and package file' do it 'updates package and package file' do
subject subject
expect(package.reload.name).to eq(package_name) expect(package.reload.name).to eq(package_name)
expect(package.version).to eq(package_version) expect(package.version).to eq(package_version)
expect(package_file.reload.file_name).to eq(package_file_name) expect(package_file.reload.file_name).to eq(package_file_name)
# hard reset needed to properly reload package_file.file
expect(Packages::PackageFile.find(package_file.id).file.size).not_to eq 0
end end
context 'with exisiting package' do context 'with exisiting package' do
......
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