I use fixture_file_upload
in my FactoryGirl
methods to test file uploads. Problem is that after cleaning the database, all these uploaded files remain on Cloudinary
.
I've been using Cloudinary::Api.delete_resources
using a rake task to get rid of them, but I'd rather immediately clean them up before DatabaseCleaner
removes all related public id's.
Where should I interfere with DatabaseCleaner
as to remove these files from Cloudinary
?
i would have two ways of doing things here.
firstly, i would not upload anything to cloudinary unless it is a integration test. i would use a mock, stub or test-double.
secondly, if you really really really need to upload the files for whatever reason, i would write a hook that does automatic cleanup in an
after_all
hook of you tests.Based on @phoet's input, and given the fact that cloudinary limits the amount of API calls you can do on a single day, as well as the amount of images you can cleanup in a single call, I created a class
which I use as follows: in my factory girl file, I make a call to immediately add any public_ids after creating an advertisement:
in env.rb, I added
as well as in spec_helper.rb
This results in, during testing, cleanup after each 100 cloudinary images, and after testing, to clean up the remainder