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
ce84d183
Commit
ce84d183
authored
Jan 30, 2018
by
Micaël Bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apply fixes from feedback
parent
2b153640
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
9 deletions
+37
-9
app/models/upload.rb
app/models/upload.rb
+1
-2
app/uploaders/file_uploader.rb
app/uploaders/file_uploader.rb
+9
-7
spec/uploaders/file_uploader_spec.rb
spec/uploaders/file_uploader_spec.rb
+27
-0
No files found.
app/models/upload.rb
View file @
ce84d183
...
@@ -30,8 +30,7 @@ class Upload < ActiveRecord::Base
...
@@ -30,8 +30,7 @@ class Upload < ActiveRecord::Base
end
end
def
build_uploader
def
build_uploader
uploader_class
.
new
(
model
,
mount_point
,
**
uploader_context
)
uploader_class
.
new
(
model
,
mount_point
,
**
uploader_context
).
tap
do
|
uploader
|
.
tap
do
|
uploader
|
uploader
.
upload
=
self
uploader
.
upload
=
self
uploader
.
retrieve_from_store!
(
identifier
)
uploader
.
retrieve_from_store!
(
identifier
)
end
end
...
...
app/uploaders/file_uploader.rb
View file @
ce84d183
...
@@ -110,14 +110,16 @@ class FileUploader < GitlabUploader
...
@@ -110,14 +110,16 @@ class FileUploader < GitlabUploader
end
end
def
upload
=
(
value
)
def
upload
=
(
value
)
unless
apply_context!
(
value
.
uploader_context
)
if
matches
=
DYNAMIC_PATH_PATTERN
.
match
(
value
.
path
)
@secret
=
matches
[
:secret
]
@identifier
=
matches
[
:identifier
]
end
end
super
super
return
unless
value
return
if
apply_context!
(
value
.
uploader_context
)
# fallback to the regex based extraction
if
matches
=
DYNAMIC_PATH_PATTERN
.
match
(
value
.
path
)
@secret
=
matches
[
:secret
]
@identifier
=
matches
[
:identifier
]
end
end
end
def
secret
def
secret
...
...
spec/uploaders/file_uploader_spec.rb
View file @
ce84d183
...
@@ -54,4 +54,31 @@ describe FileUploader do
...
@@ -54,4 +54,31 @@ describe FileUploader do
expect
(
uploader
.
secret
).
to
eq
(
'secret'
)
expect
(
uploader
.
secret
).
to
eq
(
'secret'
)
end
end
end
end
describe
'#upload='
do
let
(
:secret
)
{
SecureRandom
.
hex
}
let
(
:upload
)
{
create
(
:upload
,
:issuable_upload
,
secret:
secret
,
filename:
'file.txt'
)
}
it
'handles nil'
do
expect
(
uploader
).
not_to
receive
(
:apply_context!
)
uploader
.
upload
=
nil
end
it
'extract the uploader context from it'
do
expect
(
uploader
).
to
receive
(
:apply_context!
).
with
(
a_hash_including
(
secret:
secret
,
identifier:
'file.txt'
))
uploader
.
upload
=
upload
end
context
'uploader_context is empty'
do
it
'fallbacks to regex based extraction'
do
expect
(
upload
).
to
receive
(
:uploader_context
).
and_return
({})
uploader
.
upload
=
upload
expect
(
uploader
.
secret
).
to
eq
(
secret
)
expect
(
uploader
.
instance_variable_get
(
:@identifier
)).
to
eq
(
'file.txt'
)
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