Commit 1ebf531a authored by Kerri Miller's avatar Kerri Miller

Merge branch 'package_uploader_refactor' into 'master'

Update package_file to use FileStoreMounter concern

See merge request gitlab-org/gitlab!48482
parents 3cd615b6 3b941e0d
# frozen_string_literal: true
class Packages::PackageFile < ApplicationRecord
include UpdateProjectStatistics
include FileStoreMounter
delegate :project, :project_id, to: :package
delegate :conan_file_type, to: :conan_file_metadatum
......@@ -35,20 +36,12 @@ class Packages::PackageFile < ApplicationRecord
.where(packages_conan_file_metadata: { conan_package_reference: conan_package_reference })
end
mount_uploader :file, Packages::PackageFileUploader
after_save :update_file_metadata, if: :saved_change_to_file?
mount_file_store_uploader Packages::PackageFileUploader
update_project_statistics project_statistics_name: :packages_size
before_save :update_size_from_file
def update_file_metadata
# The file.object_store is set during `uploader.store!`
# which happens after object is inserted/updated
self.update_column(:file_store, file.object_store)
end
def download_path
Gitlab::Routing.url_helpers.download_project_package_file_path(project, self)
end
......
......@@ -61,14 +61,14 @@ RSpec.describe Packages::PackageFile, type: :model do
end
end
describe '#update_file_metadata callback' do
describe '#update_file_store callback' do
let_it_be(:package_file) { build(:package_file, :nuget, size: nil) }
subject { package_file.save! }
it 'updates metadata columns' do
expect(package_file)
.to receive(:update_file_metadata)
.to receive(:update_file_store)
.and_call_original
# This expectation uses a stub because we can no longer test a change from
......
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