aboutsummaryrefslogtreecommitdiffstats
path: root/test/service
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2017-07-06 07:53:26 -0400
committerGeorge Claghorn <george@basecamp.com>2017-07-06 07:53:26 -0400
commit7341d9100985b59d14afb804c71826d6617bba7e (patch)
tree04c6dab51b3c34e2690827be3773a2c995ebf04c /test/service
parenta8e849bb0d621f300fb5239699749e7b88e3cf03 (diff)
downloadrails-7341d9100985b59d14afb804c71826d6617bba7e.tar.gz
rails-7341d9100985b59d14afb804c71826d6617bba7e.tar.bz2
rails-7341d9100985b59d14afb804c71826d6617bba7e.zip
Flesh out mirror tests
Diffstat (limited to 'test/service')
-rw-r--r--test/service/mirror_service_test.rb33
1 files changed, 26 insertions, 7 deletions
diff --git a/test/service/mirror_service_test.rb b/test/service/mirror_service_test.rb
index 3b22c4f049..95fe369a4c 100644
--- a/test/service/mirror_service_test.rb
+++ b/test/service/mirror_service_test.rb
@@ -9,12 +9,10 @@ class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
include ActiveStorage::Service::SharedServiceTests
- test "uploading was done to all services" do
+ test "uploading to all services" do
begin
- key = SecureRandom.base58(24)
data = "Something else entirely!"
- io = StringIO.new(data)
- @service.upload(key, io)
+ key = upload(data, to: @service)
assert_equal data, PRIMARY_DISK_SERVICE.download(key)
assert_equal data, SECONDARY_DISK_SERVICE.download(key)
@@ -23,8 +21,29 @@ class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
end
end
- test "existing in all services" do
- assert PRIMARY_DISK_SERVICE.exist?(FIXTURE_KEY)
- assert SECONDARY_DISK_SERVICE.exist?(FIXTURE_KEY)
+ test "downloading from primary service" do
+ data = "Something else entirely!"
+ key = upload(data, to: PRIMARY_DISK_SERVICE)
+
+ assert_equal data, @service.download(key)
+ end
+
+ test "deleting from all services" do
+ @service.delete FIXTURE_KEY
+ assert_not PRIMARY_DISK_SERVICE.exist?(FIXTURE_KEY)
+ assert_not SECONDARY_DISK_SERVICE.exist?(FIXTURE_KEY)
+ end
+
+ test "URL generation in primary service" do
+ travel_to Time.now do
+ assert_equal PRIMARY_DISK_SERVICE.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: "test.txt"),
+ @service.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: "test.txt")
+ end
+ end
+
+ def upload(data, to:)
+ SecureRandom.base58(24).tap do |key|
+ @service.upload key, StringIO.new(data)
+ end
end
end