1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/test/disk_site_test.rb
David Heinemeier Hansson 1e05e62856 Test basic upload
2017-07-01 14:24:43 +02:00

51 lines
1.2 KiB
Ruby

require "test_helper"
require "fileutils"
require "tmpdir"
require "active_support/core_ext/securerandom"
require "active_file/site"
class ActiveFile::DiskSiteTest < ActiveSupport::TestCase
FIXTURE_KEY = SecureRandom.base58(24)
FIXTURE_FILE = StringIO.new("Hello world!")
setup do
@site = ActiveFile::Sites::DiskSite.new(File.join(Dir.tmpdir, "active_file"))
@site.upload FIXTURE_KEY, FIXTURE_FILE
FIXTURE_FILE.rewind
end
teardown do
FileUtils.rm_rf @site.root
FIXTURE_FILE.rewind
end
test "uploading" do
key = SecureRandom.base58(24)
data = "Something else entirely!"
@site.upload(key, StringIO.new(data))
assert_equal data, @site.download(key)
end
test "downloading" do
assert_equal FIXTURE_FILE.read, @site.download(FIXTURE_KEY)
end
test "existing" do
assert @site.exists?(FIXTURE_KEY)
assert_not @site.exists?(FIXTURE_KEY + "nonsense")
end
test "deleting" do
@site.delete FIXTURE_KEY
assert_not @site.exists?(FIXTURE_KEY)
end
test "sizing" do
assert_equal FIXTURE_FILE.size, @site.byte_size(FIXTURE_KEY)
end
test "checksumming" do
assert_equal Digest::MD5.hexdigest(FIXTURE_FILE.read), @site.checksum(FIXTURE_KEY)
end
end