aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test
diff options
context:
space:
mode:
authorCameron Bothner <cameronbothner@gmail.com>2018-08-18 13:31:33 -0400
committerCameron Bothner <cameronbothner@gmail.com>2018-08-21 15:31:14 -0400
commit5cd2d07bdcda4b2f547830d2becafe5e0722fa43 (patch)
tree78cd529618c2032f1f9049ae2b1c052eaaf23800 /activestorage/test
parent87d5415f0aa3e6f9f74f645a47370dd854375a1a (diff)
downloadrails-5cd2d07bdcda4b2f547830d2becafe5e0722fa43.tar.gz
rails-5cd2d07bdcda4b2f547830d2becafe5e0722fa43.tar.bz2
rails-5cd2d07bdcda4b2f547830d2becafe5e0722fa43.zip
Translate service-specific missing object exceptions into a generic one
`ActiveStorage::Blob#download` and `ActiveStorage::Blob#open` raise `ActiveStorage::FileNotFoundError` when the corresponding file is missing from the storage service. Services translate service-specific missing object exceptions (e.g. `Google::Cloud::NotFoundError` for the GCS service and `Errno::ENOENT` for the disk service) into `ActiveStorage::FileNotFoundError`.
Diffstat (limited to 'activestorage/test')
-rw-r--r--activestorage/test/service/shared_service_tests.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/activestorage/test/service/shared_service_tests.rb b/activestorage/test/service/shared_service_tests.rb
index 30cfca4e36..58f189af2b 100644
--- a/activestorage/test/service/shared_service_tests.rb
+++ b/activestorage/test/service/shared_service_tests.rb
@@ -50,6 +50,13 @@ module ActiveStorage::Service::SharedServiceTests
assert_equal FIXTURE_DATA, @service.download(@key)
end
+ test "downloading a nonexistent file" do
+ assert_raises(ActiveStorage::FileNotFoundError) do
+ @service.download(SecureRandom.base58(24))
+ end
+ end
+
+
test "downloading in chunks" do
key = SecureRandom.base58(24)
expected_chunks = [ "a" * 5.megabytes, "b" ]
@@ -68,11 +75,25 @@ module ActiveStorage::Service::SharedServiceTests
end
end
+ test "downloading a nonexistent file in chunks" do
+ assert_raises(ActiveStorage::FileNotFoundError) do
+ @service.download(SecureRandom.base58(24)) {}
+ end
+ end
+
+
test "downloading partially" do
assert_equal "\x10\x00\x00", @service.download_chunk(@key, 19..21)
assert_equal "\x10\x00\x00", @service.download_chunk(@key, 19...22)
end
+ test "partially downloading a nonexistent file" do
+ assert_raises(ActiveStorage::FileNotFoundError) do
+ @service.download_chunk(SecureRandom.base58(24), 19..21)
+ end
+ end
+
+
test "existing" do
assert @service.exist?(@key)
assert_not @service.exist?(@key + "nonsense")