Immediate avatar and embed variants
Process variants synchronously on attachment to close the window between image upload and variant availability, guaranteeing that we won't have lazy variant processing attempts in GET requests. Tradeoff is that we do variant processing in upload requests, which is actually desirable. We're working with images that should take milliseconds to resize given that we'll already have the file on hand. References https://github.com/rails/rails/pull/51951
This commit is contained in:
@@ -27,7 +27,9 @@ class Users::AvatarsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "show own image redirects to the blob url" do
|
||||
users(:david).avatar.attach(io: File.open(file_fixture("moon.jpg")), filename: "moon.jpg", content_type: "image/jpeg")
|
||||
# Create blob separately to ensure file is uploaded before variant processing
|
||||
blob = ActiveStorage::Blob.create_and_upload!(io: File.open(file_fixture("moon.jpg")), filename: "moon.jpg", content_type: "image/jpeg")
|
||||
users(:david).avatar.attach(blob)
|
||||
assert users(:david).avatar.attached?
|
||||
|
||||
get user_avatar_path(users(:david))
|
||||
@@ -36,7 +38,9 @@ class Users::AvatarsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "show other image redirects to the blob url" do
|
||||
users(:kevin).avatar.attach(io: File.open(file_fixture("moon.jpg")), filename: "moon.jpg", content_type: "image/jpeg")
|
||||
# Create blob separately to ensure file is uploaded before variant processing
|
||||
blob = ActiveStorage::Blob.create_and_upload!(io: File.open(file_fixture("moon.jpg")), filename: "moon.jpg", content_type: "image/jpeg")
|
||||
users(:kevin).avatar.attach(blob)
|
||||
assert users(:kevin).avatar.attached?
|
||||
|
||||
get user_avatar_path(users(:kevin))
|
||||
|
||||
Reference in New Issue
Block a user