Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
82356233
Commit
82356233
authored
7 years ago
by
Matt Jankowski
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve spec coverage and clean up api/v1/media controller (#3467)
parent
83435c49
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/controllers/api/v1/media_controller.rb
+11
-3
11 additions, 3 deletions
app/controllers/api/v1/media_controller.rb
spec/controllers/api/v1/media_controller_spec.rb
+24
-0
24 additions, 0 deletions
spec/controllers/api/v1/media_controller_spec.rb
with
35 additions
and
3 deletions
app/controllers/api/v1/media_controller.rb
+
11
−
3
View file @
82356233
...
...
@@ -10,11 +10,11 @@ class Api::V1::MediaController < ApiController
respond_to
:json
def
create
@media
=
M
edia
A
ttachment
.
create!
(
account:
current_user
.
account
,
file:
media_params
[
:file
])
@media
=
current_account
.
m
edia
_a
ttachment
s
.
create!
(
file:
media_params
[
:file
])
rescue
Paperclip
::
Errors
::
NotIdentifiedByImageMagickError
render
json:
{
error:
'F
ile
type
of uploaded media could not be verified'
}
,
status:
422
render
json:
f
ile
_
type
_error
,
status:
422
rescue
Paperclip
::
Error
render
json:
{
error:
'Error processing thumbnail for uploaded media'
}
,
status:
500
render
json:
processing_error
,
status:
500
end
private
...
...
@@ -22,4 +22,12 @@ class Api::V1::MediaController < ApiController
def
media_params
params
.
permit
(
:file
)
end
def
file_type_error
{
error:
'File type of uploaded media could not be verified'
}
end
def
processing_error
{
error:
'Error processing thumbnail for uploaded media'
}
end
end
This diff is collapsed.
Click to expand it.
spec/controllers/api/v1/media_controller_spec.rb
+
24
−
0
View file @
82356233
...
...
@@ -11,6 +11,30 @@ RSpec.describe Api::V1::MediaController, type: :controller do
end
describe
'POST #create'
do
describe
'with paperclip errors'
do
context
'when imagemagick cant identify the file type'
do
before
do
expect_any_instance_of
(
Account
).
to
receive_message_chain
(
:media_attachments
,
:create!
).
and_raise
(
Paperclip
::
Errors
::
NotIdentifiedByImageMagickError
)
post
:create
,
params:
{
file:
fixture_file_upload
(
'files/attachment.jpg'
,
'image/jpeg'
)
}
end
it
'returns http 422'
do
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
end
end
context
'when there is a generic error'
do
before
do
expect_any_instance_of
(
Account
).
to
receive_message_chain
(
:media_attachments
,
:create!
).
and_raise
(
Paperclip
::
Error
)
post
:create
,
params:
{
file:
fixture_file_upload
(
'files/attachment.jpg'
,
'image/jpeg'
)
}
end
it
'returns http 422'
do
expect
(
response
).
to
have_http_status
(
:error
)
end
end
end
context
'image/jpeg'
do
before
do
post
:create
,
params:
{
file:
fixture_file_upload
(
'files/attachment.jpg'
,
'image/jpeg'
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment