1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/test/blob_test.rb
David Heinemeier Hansson a19d943f1d Direct uploads for S3
2017-07-09 18:03:13 +02:00

28 lines
905 B
Ruby

require "test_helper"
require "database/setup"
require "active_storage/blob"
class ActiveStorage::BlobTest < ActiveSupport::TestCase
test "create after upload sets byte size and checksum" do
data = "Hello world!"
blob = create_blob data: data
assert_equal data, blob.download
assert_equal data.length, blob.byte_size
assert_equal Digest::MD5.base64digest(data), blob.checksum
end
test "urls expiring in 5 minutes" do
blob = create_blob
travel_to Time.now do
assert_equal expected_url_for(blob), blob.url
assert_equal expected_url_for(blob, disposition: :attachment), blob.url(disposition: :attachment)
end
end
private
def expected_url_for(blob, disposition: :inline)
"/rails/active_storage/disk/#{ActiveStorage::VerifiedKeyWithExpiration.encode(blob.key, expires_in: 5.minutes)}/#{blob.filename}?disposition=#{disposition}"
end
end