about summary refs log tree commit diff
path: root/spec/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 /spec/controllers
parent83435c49ea4f31d80d81658d8faa69ed5350e26f (diff)
Improve spec coverage and clean up api/v1/media controller (#3467)
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/api/v1/media_controller_spec.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/controllers/api/v1/media_controller_spec.rb b/spec/controllers/api/v1/media_controller_spec.rb
index b1d9798ea..00dcac95d 100644
--- a/spec/controllers/api/v1/media_controller_spec.rb
+++ b/spec/controllers/api/v1/media_controller_spec.rb
@@ -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') }