aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test
diff options
context:
space:
mode:
Diffstat (limited to 'activestorage/test')
-rwxr-xr-xactivestorage/test/dummy/bin/yarn12
-rw-r--r--activestorage/test/dummy/config/application.rb2
-rw-r--r--activestorage/test/dummy/config/environments/development.rb1
-rw-r--r--activestorage/test/fixtures/files/racecar.tifbin0 -> 33705838 bytes
-rw-r--r--activestorage/test/models/attached/many_test.rb2
-rw-r--r--activestorage/test/models/attached/one_test.rb2
-rw-r--r--activestorage/test/models/blob_test.rb4
-rw-r--r--activestorage/test/models/variant_test.rb119
-rw-r--r--activestorage/test/service/azure_storage_service_test.rb24
-rw-r--r--activestorage/test/service/gcs_service_test.rb108
-rw-r--r--activestorage/test/service/mirror_service_test.rb24
-rw-r--r--activestorage/test/service/s3_service_test.rb32
-rw-r--r--activestorage/test/service/shared_service_tests.rb86
13 files changed, 200 insertions, 216 deletions
diff --git a/activestorage/test/dummy/bin/yarn b/activestorage/test/dummy/bin/yarn
index c9b7498378..d0dd7c27ac 100755
--- a/activestorage/test/dummy/bin/yarn
+++ b/activestorage/test/dummy/bin/yarn
@@ -3,11 +3,9 @@
VENDOR_PATH = File.expand_path("..", __dir__)
Dir.chdir(VENDOR_PATH) do
- begin
- exec "yarnpkg #{ARGV.join(" ")}"
- rescue Errno::ENOENT
- $stderr.puts "Yarn executable was not detected in the system."
- $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
- exit 1
- end
+ exec "yarnpkg #{ARGV.join(" ")}"
+rescue Errno::ENOENT
+ $stderr.puts "Yarn executable was not detected in the system."
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
+ exit 1
end
diff --git a/activestorage/test/dummy/config/application.rb b/activestorage/test/dummy/config/application.rb
index bd14ac0b1a..151c8ade4b 100644
--- a/activestorage/test/dummy/config/application.rb
+++ b/activestorage/test/dummy/config/application.rb
@@ -15,7 +15,7 @@ Bundler.require(*Rails.groups)
module Dummy
class Application < Rails::Application
- config.load_defaults 5.2
+ config.load_defaults 6.0
config.active_storage.service = :local
end
diff --git a/activestorage/test/dummy/config/environments/development.rb b/activestorage/test/dummy/config/environments/development.rb
index 47fc5bf25c..4b80d291ca 100644
--- a/activestorage/test/dummy/config/environments/development.rb
+++ b/activestorage/test/dummy/config/environments/development.rb
@@ -17,6 +17,7 @@ Rails.application.configure do
# Enable/disable caching. By default caching is disabled.
if Rails.root.join("tmp/caching-dev.txt").exist?
config.action_controller.perform_caching = true
+ config.action_controller.enable_fragment_cache_logging = true
config.cache_store = :memory_store
config.public_file_server.headers = {
diff --git a/activestorage/test/fixtures/files/racecar.tif b/activestorage/test/fixtures/files/racecar.tif
new file mode 100644
index 0000000000..0a11b22896
--- /dev/null
+++ b/activestorage/test/fixtures/files/racecar.tif
Binary files differ
diff --git a/activestorage/test/models/attached/many_test.rb b/activestorage/test/models/attached/many_test.rb
index 3b563b3fc8..8fede0e682 100644
--- a/activestorage/test/models/attached/many_test.rb
+++ b/activestorage/test/models/attached/many_test.rb
@@ -590,7 +590,7 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase
assert_equal "town.jpg", @user.highlights.first.filename.to_s
assert_equal "funky.jpg", @user.highlights.second.filename.to_s
ensure
- User.send(:remove_method, :highlights)
+ User.remove_method :highlights
end
end
end
diff --git a/activestorage/test/models/attached/one_test.rb b/activestorage/test/models/attached/one_test.rb
index 561c3e9d23..7fb3262781 100644
--- a/activestorage/test/models/attached/one_test.rb
+++ b/activestorage/test/models/attached/one_test.rb
@@ -507,7 +507,7 @@ class ActiveStorage::OneAttachedTest < ActiveSupport::TestCase
assert_equal "gpj.yknuf", @user.avatar
ensure
- User.send(:remove_method, :avatar)
+ User.remove_method :avatar
end
end
end
diff --git a/activestorage/test/models/blob_test.rb b/activestorage/test/models/blob_test.rb
index 1503f5fc50..54cf9e2b8a 100644
--- a/activestorage/test/models/blob_test.rb
+++ b/activestorage/test/models/blob_test.rb
@@ -47,6 +47,10 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
assert_equal "text/csv", blob.content_type
end
+ test "create after upload generates a 28-character base36 key" do
+ assert_match(/^[a-z0-9]{28}$/, create_blob.key)
+ end
+
test "image?" do
blob = create_file_blob filename: "racecar.jpg"
assert_predicate blob, :image?
diff --git a/activestorage/test/models/variant_test.rb b/activestorage/test/models/variant_test.rb
index 8552080e7b..d98935eb9f 100644
--- a/activestorage/test/models/variant_test.rb
+++ b/activestorage/test/models/variant_test.rb
@@ -26,16 +26,14 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
end
test "monochrome with default variant_processor" do
- begin
- ActiveStorage.variant_processor = nil
-
- blob = create_file_blob(filename: "racecar.jpg")
- variant = blob.variant(monochrome: true).processed
- image = read_image(variant)
- assert_match(/Gray/, image.colorspace)
- ensure
- ActiveStorage.variant_processor = :mini_magick
- end
+ ActiveStorage.variant_processor = nil
+
+ blob = create_file_blob(filename: "racecar.jpg")
+ variant = blob.variant(monochrome: true).processed
+ image = read_image(variant)
+ assert_match(/Gray/, image.colorspace)
+ ensure
+ ActiveStorage.variant_processor = :mini_magick
end
test "disabled variation of JPEG blob" do
@@ -66,45 +64,41 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
end
test "disabled variation using :combine_options" do
- begin
- ActiveStorage.variant_processor = nil
- blob = create_file_blob(filename: "racecar.jpg")
- variant = ActiveSupport::Deprecation.silence do
- blob.variant(combine_options: {
- crop: "100x100+0+0",
- monochrome: false
- }).processed
- end
- assert_match(/racecar\.jpg/, variant.service_url)
-
- image = read_image(variant)
- assert_equal 100, image.width
- assert_equal 100, image.height
- assert_match(/RGB/, image.colorspace)
- ensure
- ActiveStorage.variant_processor = :mini_magick
+ ActiveStorage.variant_processor = nil
+ blob = create_file_blob(filename: "racecar.jpg")
+ variant = ActiveSupport::Deprecation.silence do
+ blob.variant(combine_options: {
+ crop: "100x100+0+0",
+ monochrome: false
+ }).processed
end
+ assert_match(/racecar\.jpg/, variant.service_url)
+
+ image = read_image(variant)
+ assert_equal 100, image.width
+ assert_equal 100, image.height
+ assert_match(/RGB/, image.colorspace)
+ ensure
+ ActiveStorage.variant_processor = :mini_magick
end
test "center-weighted crop of JPEG blob using :combine_options" do
- begin
- ActiveStorage.variant_processor = nil
- blob = create_file_blob(filename: "racecar.jpg")
- variant = ActiveSupport::Deprecation.silence do
- blob.variant(combine_options: {
- gravity: "center",
- resize: "100x100^",
- crop: "100x100+0+0",
- }).processed
- end
- assert_match(/racecar\.jpg/, variant.service_url)
-
- image = read_image(variant)
- assert_equal 100, image.width
- assert_equal 100, image.height
- ensure
- ActiveStorage.variant_processor = :mini_magick
+ ActiveStorage.variant_processor = nil
+ blob = create_file_blob(filename: "racecar.jpg")
+ variant = ActiveSupport::Deprecation.silence do
+ blob.variant(combine_options: {
+ gravity: "center",
+ resize: "100x100^",
+ crop: "100x100+0+0",
+ }).processed
end
+ assert_match(/racecar\.jpg/, variant.service_url)
+
+ image = read_image(variant)
+ assert_equal 100, image.width
+ assert_equal 100, image.height
+ ensure
+ ActiveStorage.variant_processor = :mini_magick
end
test "center-weighted crop of JPEG blob using :resize_to_fill" do
@@ -139,6 +133,17 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
assert_equal 20, image.height
end
+ test "resized variation of TIFF blob" do
+ blob = create_file_blob(filename: "racecar.tif")
+ variant = blob.variant(resize: "50x50").processed
+ assert_match(/racecar\.png/, variant.service_url)
+
+ image = read_image(variant)
+ assert_equal "PNG", image.type
+ assert_equal 50, image.width
+ assert_equal 33, image.height
+ end
+
test "optimized variation of GIF blob" do
blob = create_file_blob(filename: "image.gif", content_type: "image/gif")
@@ -156,22 +161,20 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
test "service_url doesn't grow in length despite long variant options" do
blob = create_file_blob(filename: "racecar.jpg")
variant = blob.variant(font: "a" * 10_000).processed
- assert_operator variant.service_url.length, :<, 726
+ assert_operator variant.service_url.length, :<, 730
end
test "works for vips processor" do
- begin
- ActiveStorage.variant_processor = :vips
- blob = create_file_blob(filename: "racecar.jpg")
- variant = blob.variant(thumbnail_image: 100).processed
-
- image = read_image(variant)
- assert_equal 100, image.width
- assert_equal 67, image.height
- rescue LoadError
- # libvips not installed
- ensure
- ActiveStorage.variant_processor = :mini_magick
- end
+ ActiveStorage.variant_processor = :vips
+ blob = create_file_blob(filename: "racecar.jpg")
+ variant = blob.variant(thumbnail_image: 100).processed
+
+ image = read_image(variant)
+ assert_equal 100, image.width
+ assert_equal 67, image.height
+ rescue LoadError
+ # libvips not installed
+ ensure
+ ActiveStorage.variant_processor = :mini_magick
end
end
diff --git a/activestorage/test/service/azure_storage_service_test.rb b/activestorage/test/service/azure_storage_service_test.rb
index 09c2e7f99c..2b07902d07 100644
--- a/activestorage/test/service/azure_storage_service_test.rb
+++ b/activestorage/test/service/azure_storage_service_test.rb
@@ -18,20 +18,18 @@ if SERVICE_CONFIGURATIONS[:azure]
end
test "uploading a tempfile" do
- begin
- key = SecureRandom.base58(24)
- data = "Something else entirely!"
-
- Tempfile.open do |file|
- file.write(data)
- file.rewind
- @service.upload(key, file)
- end
-
- assert_equal data, @service.download(key)
- ensure
- @service.delete(key)
+ key = SecureRandom.base58(24)
+ data = "Something else entirely!"
+
+ Tempfile.open do |file|
+ file.write(data)
+ file.rewind
+ @service.upload(key, file)
end
+
+ assert_equal data, @service.download(key)
+ ensure
+ @service.delete(key)
end
end
else
diff --git a/activestorage/test/service/gcs_service_test.rb b/activestorage/test/service/gcs_service_test.rb
index af27946357..6bca428f50 100644
--- a/activestorage/test/service/gcs_service_test.rb
+++ b/activestorage/test/service/gcs_service_test.rb
@@ -10,74 +10,66 @@ if SERVICE_CONFIGURATIONS[:gcs]
include ActiveStorage::Service::SharedServiceTests
test "direct upload" do
- begin
- key = SecureRandom.base58(24)
- data = "Something else entirely!"
- checksum = Digest::MD5.base64digest(data)
- url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size, checksum: checksum)
-
- uri = URI.parse url
- request = Net::HTTP::Put.new uri.request_uri
- request.body = data
- request.add_field "Content-Type", ""
- request.add_field "Content-MD5", checksum
- Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
- http.request request
- end
-
- assert_equal data, @service.download(key)
- ensure
- @service.delete key
+ key = SecureRandom.base58(24)
+ data = "Something else entirely!"
+ checksum = Digest::MD5.base64digest(data)
+ url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size, checksum: checksum)
+
+ uri = URI.parse url
+ request = Net::HTTP::Put.new uri.request_uri
+ request.body = data
+ request.add_field "Content-Type", ""
+ request.add_field "Content-MD5", checksum
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
+ http.request request
end
+
+ assert_equal data, @service.download(key)
+ ensure
+ @service.delete key
end
test "upload with content_type and content_disposition" do
- begin
- key = SecureRandom.base58(24)
- data = "Something else entirely!"
-
- @service.upload(key, StringIO.new(data), checksum: Digest::MD5.base64digest(data), disposition: :attachment, filename: ActiveStorage::Filename.new("test.txt"), content_type: "text/plain")
-
- url = @service.url(key, expires_in: 2.minutes, disposition: :inline, content_type: "text/html", filename: ActiveStorage::Filename.new("test.html"))
- response = Net::HTTP.get_response(URI(url))
- assert_equal "text/plain", response.content_type
- assert_match(/attachment;.*test.txt/, response["Content-Disposition"])
- ensure
- @service.delete key
- end
+ key = SecureRandom.base58(24)
+ data = "Something else entirely!"
+
+ @service.upload(key, StringIO.new(data), checksum: Digest::MD5.base64digest(data), disposition: :attachment, filename: ActiveStorage::Filename.new("test.txt"), content_type: "text/plain")
+
+ url = @service.url(key, expires_in: 2.minutes, disposition: :inline, content_type: "text/html", filename: ActiveStorage::Filename.new("test.html"))
+ response = Net::HTTP.get_response(URI(url))
+ assert_equal "text/plain", response.content_type
+ assert_match(/attachment;.*test.txt/, response["Content-Disposition"])
+ ensure
+ @service.delete key
end
test "upload with content_type" do
- begin
- key = SecureRandom.base58(24)
- data = "Something else entirely!"
-
- @service.upload(key, StringIO.new(data), checksum: Digest::MD5.base64digest(data), content_type: "text/plain")
-
- url = @service.url(key, expires_in: 2.minutes, disposition: :inline, content_type: "text/html", filename: ActiveStorage::Filename.new("test.html"))
- response = Net::HTTP.get_response(URI(url))
- assert_equal "text/plain", response.content_type
- assert_match(/inline;.*test.html/, response["Content-Disposition"])
- ensure
- @service.delete key
- end
+ key = SecureRandom.base58(24)
+ data = "Something else entirely!"
+
+ @service.upload(key, StringIO.new(data), checksum: Digest::MD5.base64digest(data), content_type: "text/plain")
+
+ url = @service.url(key, expires_in: 2.minutes, disposition: :inline, content_type: "text/html", filename: ActiveStorage::Filename.new("test.html"))
+ response = Net::HTTP.get_response(URI(url))
+ assert_equal "text/plain", response.content_type
+ assert_match(/inline;.*test.html/, response["Content-Disposition"])
+ ensure
+ @service.delete key
end
test "update metadata" do
- begin
- key = SecureRandom.base58(24)
- data = "Something else entirely!"
- @service.upload(key, StringIO.new(data), checksum: Digest::MD5.base64digest(data), disposition: :attachment, filename: ActiveStorage::Filename.new("test.html"), content_type: "text/html")
-
- @service.update_metadata(key, disposition: :inline, filename: ActiveStorage::Filename.new("test.txt"), content_type: "text/plain")
- url = @service.url(key, expires_in: 2.minutes, disposition: :attachment, content_type: "text/html", filename: ActiveStorage::Filename.new("test.html"))
-
- response = Net::HTTP.get_response(URI(url))
- assert_equal "text/plain", response.content_type
- assert_match(/inline;.*test.txt/, response["Content-Disposition"])
- ensure
- @service.delete key
- end
+ key = SecureRandom.base58(24)
+ data = "Something else entirely!"
+ @service.upload(key, StringIO.new(data), checksum: Digest::MD5.base64digest(data), disposition: :attachment, filename: ActiveStorage::Filename.new("test.html"), content_type: "text/html")
+
+ @service.update_metadata(key, disposition: :inline, filename: ActiveStorage::Filename.new("test.txt"), content_type: "text/plain")
+ url = @service.url(key, expires_in: 2.minutes, disposition: :attachment, content_type: "text/html", filename: ActiveStorage::Filename.new("test.html"))
+
+ response = Net::HTTP.get_response(URI(url))
+ assert_equal "text/plain", response.content_type
+ assert_match(/inline;.*test.txt/, response["Content-Disposition"])
+ ensure
+ @service.delete key
end
test "signed URL generation" do
diff --git a/activestorage/test/service/mirror_service_test.rb b/activestorage/test/service/mirror_service_test.rb
index bb502dde60..94c751a4ff 100644
--- a/activestorage/test/service/mirror_service_test.rb
+++ b/activestorage/test/service/mirror_service_test.rb
@@ -18,22 +18,20 @@ class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
include ActiveStorage::Service::SharedServiceTests
test "uploading to all services" do
- begin
- key = SecureRandom.base58(24)
- data = "Something else entirely!"
- io = StringIO.new(data)
- checksum = Digest::MD5.base64digest(data)
+ key = SecureRandom.base58(24)
+ data = "Something else entirely!"
+ io = StringIO.new(data)
+ checksum = Digest::MD5.base64digest(data)
- @service.upload key, io.tap(&:read), checksum: checksum
- assert_predicate io, :eof?
+ @service.upload key, io.tap(&:read), checksum: checksum
+ assert_predicate io, :eof?
- assert_equal data, @service.primary.download(key)
- @service.mirrors.each do |mirror|
- assert_equal data, mirror.download(key)
- end
- ensure
- @service.delete key
+ assert_equal data, @service.primary.download(key)
+ @service.mirrors.each do |mirror|
+ assert_equal data, mirror.download(key)
end
+ ensure
+ @service.delete key
end
test "downloading from primary service" do
diff --git a/activestorage/test/service/s3_service_test.rb b/activestorage/test/service/s3_service_test.rb
index 0e5b06dd78..0a6004267f 100644
--- a/activestorage/test/service/s3_service_test.rb
+++ b/activestorage/test/service/s3_service_test.rb
@@ -11,25 +11,23 @@ if SERVICE_CONFIGURATIONS[:s3]
include ActiveStorage::Service::SharedServiceTests
test "direct upload" do
- begin
- key = SecureRandom.base58(24)
- data = "Something else entirely!"
- checksum = Digest::MD5.base64digest(data)
- url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size, checksum: checksum)
-
- uri = URI.parse url
- request = Net::HTTP::Put.new uri.request_uri
- request.body = data
- request.add_field "Content-Type", "text/plain"
- request.add_field "Content-MD5", checksum
- Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
- http.request request
- end
+ key = SecureRandom.base58(24)
+ data = "Something else entirely!"
+ checksum = Digest::MD5.base64digest(data)
+ url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size, checksum: checksum)
- assert_equal data, @service.download(key)
- ensure
- @service.delete key
+ uri = URI.parse url
+ request = Net::HTTP::Put.new uri.request_uri
+ request.body = data
+ request.add_field "Content-Type", "text/plain"
+ request.add_field "Content-MD5", checksum
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
+ http.request request
end
+
+ assert_equal data, @service.download(key)
+ ensure
+ @service.delete key
end
test "upload a zero byte file" do
diff --git a/activestorage/test/service/shared_service_tests.rb b/activestorage/test/service/shared_service_tests.rb
index b97030b320..17f3736056 100644
--- a/activestorage/test/service/shared_service_tests.rb
+++ b/activestorage/test/service/shared_service_tests.rb
@@ -20,48 +20,42 @@ module ActiveStorage::Service::SharedServiceTests
end
test "uploading with integrity" do
- begin
- key = SecureRandom.base58(24)
- data = "Something else entirely!"
- @service.upload(key, StringIO.new(data), checksum: Digest::MD5.base64digest(data))
+ key = SecureRandom.base58(24)
+ data = "Something else entirely!"
+ @service.upload(key, StringIO.new(data), checksum: Digest::MD5.base64digest(data))
- assert_equal data, @service.download(key)
- ensure
- @service.delete key
- end
+ assert_equal data, @service.download(key)
+ ensure
+ @service.delete key
end
test "uploading without integrity" do
- begin
- key = SecureRandom.base58(24)
- data = "Something else entirely!"
+ key = SecureRandom.base58(24)
+ data = "Something else entirely!"
- assert_raises(ActiveStorage::IntegrityError) do
- @service.upload(key, StringIO.new(data), checksum: Digest::MD5.base64digest("bad data"))
- end
-
- assert_not @service.exist?(key)
- ensure
- @service.delete key
+ assert_raises(ActiveStorage::IntegrityError) do
+ @service.upload(key, StringIO.new(data), checksum: Digest::MD5.base64digest("bad data"))
end
+
+ assert_not @service.exist?(key)
+ ensure
+ @service.delete key
end
test "uploading with integrity and multiple keys" do
- begin
- key = SecureRandom.base58(24)
- data = "Something else entirely!"
- @service.upload(
- key,
- StringIO.new(data),
- checksum: Digest::MD5.base64digest(data),
- filename: "racecar.jpg",
- content_type: "image/jpg"
- )
-
- assert_equal data, @service.download(key)
- ensure
- @service.delete key
- end
+ key = SecureRandom.base58(24)
+ data = "Something else entirely!"
+ @service.upload(
+ key,
+ StringIO.new(data),
+ checksum: Digest::MD5.base64digest(data),
+ filename: "racecar.jpg",
+ content_type: "image/jpg"
+ )
+
+ assert_equal data, @service.download(key)
+ ensure
+ @service.delete key
end
test "downloading" do
@@ -129,20 +123,18 @@ module ActiveStorage::Service::SharedServiceTests
end
test "deleting by prefix" do
- begin
- @service.upload("a/a/a", StringIO.new(FIXTURE_DATA))
- @service.upload("a/a/b", StringIO.new(FIXTURE_DATA))
- @service.upload("a/b/a", StringIO.new(FIXTURE_DATA))
-
- @service.delete_prefixed("a/a/")
- assert_not @service.exist?("a/a/a")
- assert_not @service.exist?("a/a/b")
- assert @service.exist?("a/b/a")
- ensure
- @service.delete("a/a/a")
- @service.delete("a/a/b")
- @service.delete("a/b/a")
- end
+ @service.upload("a/a/a", StringIO.new(FIXTURE_DATA))
+ @service.upload("a/a/b", StringIO.new(FIXTURE_DATA))
+ @service.upload("a/b/a", StringIO.new(FIXTURE_DATA))
+
+ @service.delete_prefixed("a/a/")
+ assert_not @service.exist?("a/a/a")
+ assert_not @service.exist?("a/a/b")
+ assert @service.exist?("a/b/a")
+ ensure
+ @service.delete("a/a/a")
+ @service.delete("a/a/b")
+ @service.delete("a/b/a")
end
end
end