Aloha!
At the moment there isn't anything in Shrine specific for testing, but I can provide a few opinions that come to mind.
Firstly, what I saw in Refile that it exposed a
FileDouble for "easier" testing. Why I mention this is because Shrine conforms to the same IO interface. However, I would recommend that for testing real files are used, or IOs that are used by your application (e.g. ActionDispatch::Http::UploadedFile).
Storages are very easily tested directly, you just instantiate them with the symbol name of the registered storage:
image = File.open("test/fixtures/image.jpg")
uploader = ImageUploader.new(:store)
uploaded_file = uploader.upload(image)
# further assertions on uploaded_file
When you're testing an uploader directly, it's good to test processing. However, when you have more higher-level tests, you might want to disable processing, and in case of versions simply conform to the interface:
before do
allow_any_instance(ImageUploader).to receive(:process).and_wrap_original do |m, io, context|
if context[:phase] == :store
{small: io, medium: io, large: io}
end
end
end
For testing presigns, there has been some
discussion already. The idea was to be able to swap S3 storages with FileSystem in tests (to eliminate HTTP), and that presigns are still generated for the FileSystem storage, just returning the URL to the direct upload route. I think this will soon land in master. However, these will probably only get tested in acceptance tests, and there it might be better just to use real storages anyway.
Cheers,
Janko