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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
7549d17f
Commit
7549d17f
authored
Nov 22, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor
parent
67b58ffd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
16 deletions
+13
-16
lib/gitlab/background_migration/populate_untracked_uploads.rb
...gitlab/background_migration/populate_untracked_uploads.rb
+10
-13
spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb
...b/background_migration/populate_untracked_uploads_spec.rb
+3
-3
No files found.
lib/gitlab/background_migration/populate_untracked_uploads.rb
View file @
7549d17f
...
...
@@ -51,23 +51,20 @@ module Gitlab
].
freeze
def
ensure_tracked!
add_to_uploads
unless
in_uploads?
add_to_uploads
_if_needed
delete
end
def
in_uploads?
def
add_to_uploads_if_needed
# Even though we are checking relative paths, path is enough to
# uniquely identify uploads. There is no ambiguity between
# FileUploader paths and other Uploader paths because we use the /-/
# separator kind of like an escape character. Project full_path will
# never conflict with an upload path starting with "uploads/-/".
Upload
.
exists?
(
path:
upload_path
)
end
def
add_to_uploads
Upload
.
create!
(
path:
upload_path
,
Upload
.
where
(
path:
upload_path
).
first_or_create!
(
uploader:
uploader
,
model_type:
model_type
,
model_id:
model_id
,
...
...
spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb
View file @
7549d17f
...
...
@@ -166,7 +166,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UntrackedFile do
end
end
describe
'#add_to_uploads'
do
describe
'#add_to_uploads
_if_needed
'
do
shared_examples_for
'add_to_uploads_non_markdown_files'
do
let!
(
:expected_upload_attrs
)
{
model
.
uploads
.
first
.
attributes
.
slice
(
'path'
,
'uploader'
,
'size'
,
'checksum'
)
}
let!
(
:untracked_file
)
{
described_class
.
create!
(
path:
expected_upload_attrs
[
'path'
])
}
...
...
@@ -177,7 +177,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UntrackedFile do
it
'creates an Upload record'
do
expect
do
untracked_file
.
add_to_uploads
untracked_file
.
add_to_uploads
_if_needed
end
.
to
change
{
model
.
reload
.
uploads
.
count
}.
from
(
0
).
to
(
1
)
expect
(
model
.
uploads
.
first
.
attributes
).
to
include
(
expected_upload_attrs
)
...
...
@@ -246,7 +246,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UntrackedFile do
it
'creates an Upload record'
do
expect
do
untracked_file
.
add_to_uploads
untracked_file
.
add_to_uploads
_if_needed
end
.
to
change
{
model
.
reload
.
uploads
.
count
}.
from
(
0
).
to
(
1
)
expect
(
model
.
uploads
.
first
.
attributes
).
to
include
(
@expected_upload_attrs
)
...
...
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