Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ab588fa7
Commit
ab588fa7
authored
Feb 07, 2020
by
David Fernandez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update package file size in the after_save callback
parent
ad938b48
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
4 deletions
+34
-4
ee/app/models/packages/package_file.rb
ee/app/models/packages/package_file.rb
+5
-4
ee/spec/models/packages/package_file_spec.rb
ee/spec/models/packages/package_file_spec.rb
+21
-0
ee/spec/services/packages/conan/create_package_file_service_spec.rb
...rvices/packages/conan/create_package_file_service_spec.rb
+8
-0
No files found.
ee/app/models/packages/package_file.rb
View file @
ab588fa7
...
...
@@ -9,8 +9,6 @@ class Packages::PackageFile < ApplicationRecord
delegate
:project
,
:project_id
,
to: :package
delegate
:conan_file_type
,
to: :conan_file_metadatum
update_project_statistics
project_statistics_name: :packages_size
belongs_to
:package
has_one
:conan_file_metadatum
,
inverse_of: :package_file
...
...
@@ -36,13 +34,16 @@ class Packages::PackageFile < ApplicationRecord
with_replicator
Geo
::
PackageFileReplicator
after_save
:update_file_
store
,
if: :saved_change_to_file?
after_save
:update_file_
metadata
,
if: :saved_change_to_file?
after_create_commit
->
{
replicator
.
publish_created_event
}
def
update_file_store
update_project_statistics
project_statistics_name: :packages_size
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
)
self
.
update_column
(
:size
,
file
.
size
)
unless
file
.
size
==
self
.
size
end
def
log_geo_deleted_event
...
...
ee/spec/models/packages/package_file_spec.rb
View file @
ab588fa7
...
...
@@ -34,5 +34,26 @@ RSpec.describe Packages::PackageFile, type: :model do
it_behaves_like
'UpdateProjectStatistics'
do
subject
{
build
(
:package_file
,
:jar
,
size:
42
)
}
before
do
allow_any_instance_of
(
Packages
::
PackageFileUploader
).
to
receive
(
:size
).
and_return
(
42
)
end
end
describe
'#update_file_metadata callback'
do
let
(
:package_file
)
{
build
(
:package_file
,
:nuget
,
file_store:
0
,
size:
nil
)
}
subject
{
package_file
.
save!
}
it
'updates metadata columns'
do
expect
(
package_file
)
.
to
receive
(
:update_file_metadata
)
.
and_call_original
subject
expect
(
package_file
.
file_store
).
to
eq
1
expect
(
package_file
.
size
).
to
eq
3513
end
end
end
ee/spec/services/packages/conan/create_package_file_service_spec.rb
View file @
ab588fa7
...
...
@@ -82,6 +82,10 @@ describe Packages::Conan::CreatePackageFileService do
UploadedFile
.
new
(
file_path
,
filename:
File
.
basename
(
file_path
))
end
before
do
allow_any_instance_of
(
Packages
::
PackageFileUploader
).
to
receive
(
:size
).
and_return
(
128
)
end
it_behaves_like
'a valid package_file'
it_behaves_like
'a valid recipe_file'
end
...
...
@@ -91,6 +95,10 @@ describe Packages::Conan::CreatePackageFileService do
stub_package_file_object_storage
(
direct_upload:
true
)
end
before
do
allow_any_instance_of
(
Packages
::
PackageFileUploader
).
to
receive
(
:size
).
and_return
(
128
)
end
let
(
:tmp_object
)
do
fog_connection
.
directories
.
new
(
key:
'packages'
).
files
.
create
(
key:
"tmp/uploads/
#{
file_name
}
"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment