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
d087b4da
Commit
d087b4da
authored
Nov 21, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FileUploader should check for hashed_storage?(:attachments) to use disk_path
parent
a4072db0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
15 deletions
+45
-15
app/uploaders/file_uploader.rb
app/uploaders/file_uploader.rb
+7
-3
spec/uploaders/file_uploader_spec.rb
spec/uploaders/file_uploader_spec.rb
+38
-12
No files found.
app/uploaders/file_uploader.rb
View file @
d087b4da
...
@@ -26,11 +26,15 @@ class FileUploader < GitlabUploader
...
@@ -26,11 +26,15 @@ class FileUploader < GitlabUploader
# This is used to build Upload paths dynamically based on the model's current
# This is used to build Upload paths dynamically based on the model's current
# namespace and path, allowing us to ignore renames or transfers.
# namespace and path, allowing us to ignore renames or transfers.
#
#
# model - Object that responds to `
path_with_namespace
`
# model - Object that responds to `
full_path` and `disk_path
`
#
#
# Returns a String without a trailing slash
# Returns a String without a trailing slash
def
self
.
dynamic_path_segment
(
model
)
def
self
.
dynamic_path_segment
(
project
)
File
.
join
(
CarrierWave
.
root
,
base_dir
,
model
.
disk_path
)
if
project
.
hashed_storage?
(
:attachments
)
File
.
join
(
CarrierWave
.
root
,
base_dir
,
project
.
disk_path
)
else
File
.
join
(
CarrierWave
.
root
,
base_dir
,
project
.
full_path
)
end
end
end
attr_accessor
:model
attr_accessor
:model
...
...
spec/uploaders/file_uploader_spec.rb
View file @
d087b4da
...
@@ -28,25 +28,51 @@ describe FileUploader do
...
@@ -28,25 +28,51 @@ describe FileUploader do
end
end
context
'hashed storage'
do
context
'hashed storage'
do
let
(
:project
)
{
build_stubbed
(
:project
,
:hashed
)
}
context
'when rolled out attachments'
do
let
(
:project
)
{
build_stubbed
(
:project
,
:hashed
)
}
describe
'.absolute_path'
do
describe
'.absolute_path'
do
it
'returns the correct absolute path by building it dynamically'
do
it
'returns the correct absolute path by building it dynamically'
do
upload
=
double
(
model:
project
,
path:
'secret/foo.jpg'
)
upload
=
double
(
model:
project
,
path:
'secret/foo.jpg'
)
dynamic_segment
=
project
.
disk_path
dynamic_segment
=
project
.
disk_path
expect
(
described_class
.
absolute_path
(
upload
))
expect
(
described_class
.
absolute_path
(
upload
))
.
to
end_with
(
"
#{
dynamic_segment
}
/secret/foo.jpg"
)
.
to
end_with
(
"
#{
dynamic_segment
}
/secret/foo.jpg"
)
end
end
describe
"#store_dir"
do
it
"stores in the namespace path"
do
uploader
=
described_class
.
new
(
project
)
expect
(
uploader
.
store_dir
).
to
include
(
project
.
disk_path
)
expect
(
uploader
.
store_dir
).
not_to
include
(
"system"
)
end
end
end
end
end
describe
"#store_dir"
do
context
'when only repositories are rolled out'
do
it
"stores in the namespace path"
do
let
(
:project
)
{
build_stubbed
(
:project
,
storage_version:
Project
::
HASHED_STORAGE_FEATURES
[
:repository
])
}
uploader
=
described_class
.
new
(
project
)
expect
(
uploader
.
store_dir
).
to
include
(
project
.
disk_path
)
describe
'.absolute_path'
do
expect
(
uploader
.
store_dir
).
not_to
include
(
"system"
)
it
'returns the correct absolute path by building it dynamically'
do
upload
=
double
(
model:
project
,
path:
'secret/foo.jpg'
)
dynamic_segment
=
project
.
full_path
expect
(
described_class
.
absolute_path
(
upload
))
.
to
end_with
(
"
#{
dynamic_segment
}
/secret/foo.jpg"
)
end
end
describe
"#store_dir"
do
it
"stores in the namespace path"
do
uploader
=
described_class
.
new
(
project
)
expect
(
uploader
.
store_dir
).
to
include
(
project
.
full_path
)
expect
(
uploader
.
store_dir
).
not_to
include
(
"system"
)
end
end
end
end
end
end
end
...
...
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