21f3f72647
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
28 lines
846 B
Ruby
28 lines
846 B
Ruby
require "test_helper"
|
|
|
|
class CommentTest < ActiveSupport::TestCase
|
|
setup do
|
|
Current.session = sessions(:david)
|
|
end
|
|
|
|
test "rich text embed variants are processed immediately on attachment" do
|
|
comment = cards(:logo).comments.create!(body: "Check this out")
|
|
comment.body.body.attachables # force load
|
|
|
|
blob = ActiveStorage::Blob.create_and_upload! \
|
|
io: File.open(file_fixture("moon.jpg")),
|
|
filename: "moon.jpg",
|
|
content_type: "image/jpeg"
|
|
|
|
comment.body.body = ActionText::Content.new(comment.body.body.to_html).append_attachables(blob)
|
|
comment.save!
|
|
|
|
embed = comment.body.embeds.sole
|
|
|
|
Attachments::VARIANTS.each_key do |variant_name|
|
|
variant = embed.variant(variant_name)
|
|
assert variant.processed?, "Expected #{variant_name} variant to be processed immediately"
|
|
end
|
|
end
|
|
end
|