Commit 3b941e0d authored by Steve Abrams's avatar Steve Abrams Committed by Kerri Miller

Update package_file to use FileStoreMounter concern

parent a9cdcc34
# frozen_string_literal: true # frozen_string_literal: true
class Packages::PackageFile < ApplicationRecord class Packages::PackageFile < ApplicationRecord
include UpdateProjectStatistics include UpdateProjectStatistics
include FileStoreMounter
delegate :project, :project_id, to: :package delegate :project, :project_id, to: :package
delegate :conan_file_type, to: :conan_file_metadatum delegate :conan_file_type, to: :conan_file_metadatum
...@@ -35,20 +36,12 @@ class Packages::PackageFile < ApplicationRecord ...@@ -35,20 +36,12 @@ class Packages::PackageFile < ApplicationRecord
.where(packages_conan_file_metadata: { conan_package_reference: conan_package_reference }) .where(packages_conan_file_metadata: { conan_package_reference: conan_package_reference })
end end
mount_uploader :file, Packages::PackageFileUploader mount_file_store_uploader Packages::PackageFileUploader
after_save :update_file_metadata, if: :saved_change_to_file?
update_project_statistics project_statistics_name: :packages_size update_project_statistics project_statistics_name: :packages_size
before_save :update_size_from_file 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 def download_path
Gitlab::Routing.url_helpers.download_project_package_file_path(project, self) Gitlab::Routing.url_helpers.download_project_package_file_path(project, self)
end end
......
...@@ -61,14 +61,14 @@ RSpec.describe Packages::PackageFile, type: :model do ...@@ -61,14 +61,14 @@ RSpec.describe Packages::PackageFile, type: :model do
end end
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) } let_it_be(:package_file) { build(:package_file, :nuget, size: nil) }
subject { package_file.save! } subject { package_file.save! }
it 'updates metadata columns' do it 'updates metadata columns' do
expect(package_file) expect(package_file)
.to receive(:update_file_metadata) .to receive(:update_file_store)
.and_call_original .and_call_original
# This expectation uses a stub because we can no longer test a change from # 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