Files
once-campfire/test/controllers/accounts/logos_controller_test.rb
T
Mike Dalessio b065b40a34 Disable libvips unfuzzed operations (#226)
and add test coverage for (un)supported file types.

The avatar and logo variants move into the models and return nil for content
types that are no longer variable, so the controllers fall back to the initials
avatar and stock logo icon instead of raising `ActiveStorage::InvariableError`.
2026-07-28 11:57:57 -04:00

57 lines
1.4 KiB
Ruby

require "test_helper"
require "vips"
class Accounts::LogosControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in :david
end
test "show stock" do
get account_logo_url
assert_valid_png_response size: 512
end
test "show stock small size" do
get account_logo_url(size: :small)
assert_valid_png_response size: 192
end
test "show custom" do
accounts(:signal).update! logo: fixture_file_upload("moon.jpg", "image/jpeg")
get account_logo_url
assert_valid_png_response size: 512
end
test "show custom small size" do
accounts(:signal).update! logo: fixture_file_upload("moon.jpg", "image/jpeg")
get account_logo_url(size: :small)
assert_valid_png_response size: 192
end
test "show stock when custom logo cannot be resized" do
accounts(:signal).update! logo: fixture_file_upload("pixel.bmp", "image/bmp")
get account_logo_url
assert_valid_png_response size: 512
end
test "destroy" do
accounts(:signal).update! logo: fixture_file_upload("moon.jpg", "image/jpeg")
delete account_logo_url
assert_redirected_to edit_account_url
assert_not accounts(:signal).reload.logo.attached?
end
private
def assert_valid_png_response(size:)
assert_equal @response.headers["content-type"], "image/png"
image = ::Vips::Image.new_from_buffer(@response.body, "")
assert_equal size, image.width
assert_equal size, image.height
end
end