Skip to content

Commit

Permalink
complete debugging failing tets
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwachajr committed Jun 21, 2019
1 parent af5951f commit 73d7b68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 32 deletions.
9 changes: 5 additions & 4 deletions app/services/cloudinary_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 2 additions & 28 deletions spec/services/cloudinary_service_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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))
Expand All @@ -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
Expand Down

0 comments on commit 73d7b68

Please sign in to comment.