Fail with Shrine::Error when storage is not S3

parent 4b1e2003
...@@ -11,6 +11,10 @@ class Shrine ...@@ -11,6 +11,10 @@ class Shrine
def uppy_s3_multipart(storage_key, **options) def uppy_s3_multipart(storage_key, **options)
s3 = find_storage(storage_key) s3 = find_storage(storage_key)
unless defined?(Shrine::Storage::S3) && s3.is_a?(Shrine::Storage::S3)
fail Error, "expected storage to be a Shrine::Storage::S3, but was #{s3.inspect}"
end
::Uppy::S3Multipart::App.new( ::Uppy::S3Multipart::App.new(
bucket: s3.bucket, bucket: s3.bucket,
prefix: s3.prefix, prefix: s3.prefix,
......
require "test_helper" require "test_helper"
require "shrine" require "shrine"
require "shrine/plugins/uppy_s3_multipart" require "shrine/plugins/uppy_s3_multipart"
require "shrine/storage/s3" require "shrine/storage/s3"
require "shrine/storage/memory"
require "rack/test_app" require "rack/test_app"
describe Shrine::Plugins::UppyS3Multipart do describe Shrine::Plugins::UppyS3Multipart do
...@@ -69,4 +72,19 @@ describe Shrine::Plugins::UppyS3Multipart do ...@@ -69,4 +72,19 @@ describe Shrine::Plugins::UppyS3Multipart do
assert_equal :create_multipart_upload, client.api_requests[0][:operation_name] assert_equal :create_multipart_upload, client.api_requests[0][:operation_name]
assert_equal "public-read", client.api_requests[0][:params][:acl] assert_equal "public-read", client.api_requests[0][:params][:acl]
end end
it "works for subclass of S3 storage" do
@shrine.storages[:s3] = Class.new(Shrine::Storage::S3).new(
bucket: "my-bucket",
stub_responses: true,
)
@shrine.uppy_s3_multipart(:s3)
end
it "fails for non-S3 storage" do
@shrine.storages[:memory] = Shrine::Storage::Memory.new
assert_raises(Shrine::Error) { @shrine.uppy_s3_multipart(:memory) }
end
end end
...@@ -20,5 +20,6 @@ Gem::Specification.new do |gem| ...@@ -20,5 +20,6 @@ Gem::Specification.new do |gem|
gem.add_development_dependency "minitest" gem.add_development_dependency "minitest"
gem.add_development_dependency "rack-test_app" gem.add_development_dependency "rack-test_app"
gem.add_development_dependency "shrine", "~> 2.0" gem.add_development_dependency "shrine", "~> 2.0"
gem.add_development_dependency "shrine-memory"
gem.add_development_dependency "aws-sdk-core", "~> 3.23" gem.add_development_dependency "aws-sdk-core", "~> 3.23"
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment