rails--rails/test/service/s3_service_test.rb

37 lines
1.2 KiB
Ruby
Raw Normal View History

require "service/shared_service_tests"
2017-07-09 16:03:13 +00:00
require "httparty"
if SERVICE_CONFIGURATIONS[:s3]
class ActiveStorage::Service::S3ServiceTest < ActiveSupport::TestCase
SERVICE = ActiveStorage::Service.configure(:s3, SERVICE_CONFIGURATIONS)
include ActiveStorage::Service::SharedServiceTests
2017-07-09 15:04:37 +00:00
2017-07-09 16:03:13 +00:00
test "direct upload" do
begin
key = SecureRandom.base58(24)
data = "Something else entirely!"
2017-07-16 23:17:18 +00:00
url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size)
2017-07-09 16:03:13 +00:00
2017-07-16 23:17:18 +00:00
HTTParty.put(
2017-07-09 16:03:13 +00:00
url,
body: data,
2017-07-16 23:17:18 +00:00
headers: { "Content-Type" => "text/plain" },
2017-07-09 16:03:13 +00:00
debug_output: STDOUT
)
2017-07-09 16:03:13 +00:00
assert_equal data, @service.download(key)
ensure
@service.delete key
end
end
2017-07-09 15:04:37 +00:00
test "signed URL generation" do
assert_match /#{SERVICE_CONFIGURATIONS[:s3][:bucket]}\.s3.(\S+)?amazonaws.com.*response-content-disposition=inline.*avatar\.png/,
@service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: :inline, filename: "avatar.png")
2017-07-09 15:04:37 +00:00
end
end
else
puts "Skipping S3 Service tests because no S3 configuration was supplied"
end