From 73d7b686b2354c3ea1b9ca9c32954bde1fa4c0f3 Mon Sep 17 00:00:00 2001 From: Benjamin Wacha Date: Thu, 6 Jun 2019 15:44:50 +0300 Subject: [PATCH] complete debugging failing tets --- app/services/cloudinary_service.rb | 9 +++---- spec/services/cloudinary_service_spec.rb | 30 ++---------------------- 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/app/services/cloudinary_service.rb b/app/services/cloudinary_service.rb index 7e7b204c6e..4434a200f0 100644 --- a/app/services/cloudinary_service.rb +++ b/app/services/cloudinary_service.rb @@ -2,18 +2,19 @@ include CloudinaryHelper include ReactOnRailsHelper +# TODO: better exception handling. and error reporting class CloudinaryService class << self def upload(file, options = {}) Cloudinary::Uploader.upload(file, options) - rescue StandardError => error - puts error + rescue StandardError + nil end def delete(public_id, options = {}) Cloudinary::Uploader.destroy(public_id, options) - rescue StandardError => error - puts error + rescue StandardError + nil end end end diff --git a/spec/services/cloudinary_service_spec.rb b/spec/services/cloudinary_service_spec.rb index a24dfea313..0ed7da2f5e 100644 --- a/spec/services/cloudinary_service_spec.rb +++ b/spec/services/cloudinary_service_spec.rb @@ -1,25 +1,12 @@ # frozen_string_literal: true FILENAME = "moment.jpeg" FILE_PATH = "/spec/uploads/" -# OPTIONS = {} describe CloudinaryService do subject { described_class } describe '#upload' do - context 'has no options' do - it 'returns json response from cloudinary' do - file = File.new(File.join(::Rails.root.to_s, FILE_PATH, FILENAME)) - response = subject.upload(file) - - expect(response).to have_key("public_id") - expect(response).to have_key("secure_url") - expect(response).to have_key("signature") - expect(response["original_filename"]).to eq("moment") - end - end - - context 'has options' do + context 'successfully' do it 'returns json response from cloudinary' do file = File.new(File.join(::Rails.root.to_s, FILE_PATH, FILENAME)) response = subject.upload(file) @@ -41,7 +28,7 @@ end describe '#delete' do - context 'has no options' do + context 'successfully' do it 'returns success json response from cloudinary' do # upload image file = File.new(File.join(::Rails.root.to_s, FILE_PATH, FILENAME)) @@ -55,19 +42,6 @@ end end - context 'has options' do - it 'returns json response from cloudinary' do - # upload image - file = File.new(File.join(::Rails.root.to_s, FILE_PATH, FILENAME)) - uploaded_file = subject.upload(file) - expect(uploaded_file).to have_key("public_id") - expect(uploaded_file).to have_key("secure_url") - - response = subject.delete(uploaded_file["public_id"]) - expect(response).to eq({"result"=>"ok"}) - end - end - context 'gracefully fails' do it 'returns not found' do # upload image