Improve avatar image handling
- redirect avatar image requests to the rails_blob_url, instead of streaming them through the web app - use a thumbnail variant for avatar images - only put avatar initials behind the stale? check (not the image redirect, which would result in browsers rendering broken images when an avatar is changed, until max-age expires)
This commit is contained in:
@@ -5,19 +5,37 @@ class Users::AvatarsControllerTest < ActionDispatch::IntegrationTest
|
||||
sign_in_as :david
|
||||
end
|
||||
|
||||
test "show self without caching" do
|
||||
test "show own initials without caching" do
|
||||
get user_avatar_path(users(:david))
|
||||
assert_match "image/svg+xml", @response.content_type
|
||||
assert @response.cache_control[:private]
|
||||
assert_equal "0", @response.cache_control[:max_age]
|
||||
end
|
||||
|
||||
test "show other with caching" do
|
||||
test "show other initials with caching" do
|
||||
get user_avatar_path(users(:kevin))
|
||||
assert_match "image/svg+xml", @response.content_type
|
||||
assert_equal 30.minutes.to_s, @response.cache_control[:max_age]
|
||||
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")
|
||||
assert users(:david).avatar.attached?
|
||||
|
||||
get user_avatar_path(users(:david))
|
||||
|
||||
assert_redirected_to rails_blob_url(users(:david).avatar.variant(:thumb), disposition: "inline")
|
||||
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")
|
||||
assert users(:kevin).avatar.attached?
|
||||
|
||||
get user_avatar_path(users(:kevin))
|
||||
|
||||
assert_redirected_to rails_blob_url(users(:kevin).avatar.variant(:thumb), disposition: "inline")
|
||||
end
|
||||
|
||||
test "delete self" do
|
||||
delete user_avatar_path(users(:david))
|
||||
assert_redirected_to users(:david)
|
||||
|
||||
Reference in New Issue
Block a user