mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-08 07:40:08 +09:00
Merge pull request #331: avoid preview generation for rich-text file embeds
Reviewed and merged by GPT on behalf of DHH. Retain all media regressions and invalidate presentation caches again.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<%# Files are posted as a message's own attachment, which gets its preview when it's posted; the composer adds none to
|
||||
the rich text. One that's there anyway is shown by its name, with no preview: Action Text's partial links to a URL
|
||||
that makes one on view, and nothing else in the app would make it. %>
|
||||
<figure class="attachment attachment--file attachment--<%= blob.filename.extension %>">
|
||||
<figcaption class="attachment__caption">
|
||||
<% if caption = blob.try(:caption) %>
|
||||
<%= caption %>
|
||||
<% else %>
|
||||
<span class="attachment__name"><%= blob.filename %></span>
|
||||
<span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
|
||||
<% end %>
|
||||
</figcaption>
|
||||
</figure>
|
||||
@@ -1,7 +1,7 @@
|
||||
<%# Be sure to check/update messages/_template.html.erb when changing this file %>
|
||||
|
||||
<%# Bump this version when the message presentation filters change what they emit. Editing this line changes the template digest, which busts BOTH this fragment cache and the collection cache that keys on this partial's digest (helper Ruby changes alone don't). %>
|
||||
<% cache [ message, "presentation-v4" ] do %>
|
||||
<% cache [ message, "presentation-v5" ] do %>
|
||||
<%= message_tag message do %>
|
||||
<h2 class="message__day-separator"><%= local_datetime_tag message.created_at, style: :date %></h2>
|
||||
|
||||
|
||||
@@ -62,6 +62,33 @@ class MessagesHelperTest < ActionView::TestCase
|
||||
assert_no_match %r{poster=|/representations/}, presentation
|
||||
end
|
||||
|
||||
test "message_presentation shows an image in the rich text as a file, rather than making its preview on view" do
|
||||
message = Message.with_attachment_details.find(message_with_file_in_rich_text("moon.jpg", "image/jpeg").id)
|
||||
|
||||
presentation = nil
|
||||
assert_no_queries_match(/active_storage_variant_records/) { presentation = view.message_presentation(message) }
|
||||
|
||||
assert_no_match %r{/representations/}, presentation
|
||||
assert_match %r{<span class="attachment__name">moon\.jpg</span>}, presentation
|
||||
end
|
||||
|
||||
test "message_presentation shows an image in the rich text as a file even when its preview was made" do
|
||||
message = message_with_file_in_rich_text("moon.jpg", "image/jpeg")
|
||||
message.body.embeds.first.blob.variant(resize_to_limit: [ 1024, 768 ]).processed
|
||||
|
||||
presentation = view.message_presentation(message.reload)
|
||||
|
||||
assert_no_match %r{/representations/}, presentation
|
||||
assert_match %r{<span class="attachment__name">moon\.jpg</span>}, presentation
|
||||
end
|
||||
|
||||
test "message_presentation shows a video in the rich text as a file" do
|
||||
presentation = view.message_presentation(message_with_file_in_rich_text("alpha-centuri.mov", "video/quicktime"))
|
||||
|
||||
assert_no_match %r{/representations/}, presentation
|
||||
assert_match %r{<span class="attachment__name">alpha-centuri\.mov</span>}, presentation
|
||||
end
|
||||
|
||||
private
|
||||
def attachment_message(file, content_type, processed:)
|
||||
attributes = { creator: users(:jason), client_message_id: "0015", attachment: fixture_file_upload(file, content_type) }
|
||||
@@ -72,4 +99,11 @@ class MessagesHelperTest < ActionView::TestCase
|
||||
rooms(:pets).messages.create!(attributes)
|
||||
end
|
||||
end
|
||||
|
||||
def message_with_file_in_rich_text(file, content_type)
|
||||
blob = ActiveStorage::Blob.create_and_upload!(io: file_fixture(file).open, filename: file, content_type: content_type)
|
||||
body = %(<div>Here: <action-text-attachment sgid="#{blob.attachable_sgid}"></action-text-attachment></div>)
|
||||
|
||||
Message.create! room: rooms(:pets), body: body, client_message_id: "0015", creator: users(:jason)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user