about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-30 21:11:29 -0400
committerGitHub <noreply@github.com>2017-05-30 21:11:29 -0400
commit82356233621300b51b3e2a2c093e9c4107e12e81 (patch)
treefaaba722c27dfaadb2a2c49b960394b4c599ca48 /app/controllers
parent83435c49ea4f31d80d81658d8faa69ed5350e26f (diff)
Improve spec coverage and clean up api/v1/media controller (#3467)
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/api/v1/media_controller.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/app/controllers/api/v1/media_controller.rb b/app/controllers/api/v1/media_controller.rb
index aed3578d7..3d7dcef42 100644
--- a/app/controllers/api/v1/media_controller.rb
+++ b/app/controllers/api/v1/media_controller.rb
@@ -10,11 +10,11 @@ class Api::V1::MediaController < ApiController
   respond_to :json
 
   def create
-    @media = MediaAttachment.create!(account: current_user.account, file: media_params[:file])
+    @media = current_account.media_attachments.create!(file: media_params[:file])
   rescue Paperclip::Errors::NotIdentifiedByImageMagickError
-    render json: { error: 'File type of uploaded media could not be verified' }, status: 422
+    render json: file_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