aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/disk_site_test.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/disk_site_test.rb b/test/disk_site_test.rb
new file mode 100644
index 0000000000..b291ae74b7
--- /dev/null
+++ b/test/disk_site_test.rb
@@ -0,0 +1,39 @@
+require "test_helper"
+require "fileutils"
+require "tmpdir"
+require "active_support/core_ext/securerandom"
+require "active_file/sites/disk_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 "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.size(FIXTURE_KEY)
+ end
+end