mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Uploading will set blob's byte size and checksum
This commit is contained in:
parent
a9d2ce5d18
commit
59d3e03b81
2 changed files with 11 additions and 4 deletions
|
@ -39,7 +39,10 @@ class ActiveFile::Blob < ActiveRecord::Base
|
||||||
|
|
||||||
|
|
||||||
def upload(data)
|
def upload(data)
|
||||||
site.upload key, data
|
site.upload(key, data)
|
||||||
|
|
||||||
|
self.checksum = site.checksum(key)
|
||||||
|
self.byte_size = site.byte_size(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
def download
|
def download
|
||||||
|
|
|
@ -5,8 +5,12 @@ require "active_file/blob"
|
||||||
ActiveFile::Blob.site = ActiveFile::Sites::DiskSite.new(File.join(Dir.tmpdir, "active_file"))
|
ActiveFile::Blob.site = ActiveFile::Sites::DiskSite.new(File.join(Dir.tmpdir, "active_file"))
|
||||||
|
|
||||||
class ActiveFile::BlobTest < ActiveSupport::TestCase
|
class ActiveFile::BlobTest < ActiveSupport::TestCase
|
||||||
test "create after upload" do
|
test "create after upload sets byte size and checksum" do
|
||||||
blob = ActiveFile::Blob.create_after_upload! data: StringIO.new("Hello world!"), filename: "hello.txt", content_type: "text/plain"
|
data = "Hello world!"
|
||||||
assert_equal "Hello world!", blob.download
|
blob = ActiveFile::Blob.create_after_upload! data: StringIO.new(data), filename: "hello.txt", content_type: "text/plain"
|
||||||
|
|
||||||
|
assert_equal data, blob.download
|
||||||
|
assert_equal data.length, blob.byte_size
|
||||||
|
assert_equal Digest::MD5.hexdigest(data), blob.checksum
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue