Implement ActiveStorage::Blob#attachable_plain_text_representation
Fixes that file attachments without captions would not be represented in plain text generated from rich-text content, causing ActionText::RichText#present? to return false. Closes #36607.
This commit is contained in:
parent
7d699dad33
commit
930402101c
|
@ -25,6 +25,10 @@ module ActionText
|
|||
def previewable_attachable?
|
||||
representable?
|
||||
end
|
||||
|
||||
def attachable_plain_text_representation(caption = nil)
|
||||
"[#{caption || filename}]"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -50,6 +50,11 @@ class ActionText::AttachmentTest < ActiveSupport::TestCase
|
|||
assert_not_nil trix_attachment.attributes["content"]
|
||||
end
|
||||
|
||||
test "converts to plain text" do
|
||||
assert_equal "[Vroom vroom]", ActionText::Attachment.from_attachable(attachable, caption: "Vroom vroom").to_plain_text
|
||||
assert_equal "[racecar.jpg]", ActionText::Attachment.from_attachable(attachable).to_plain_text
|
||||
end
|
||||
|
||||
test "defaults trix partial to model partial" do
|
||||
attachable = Page.create! title: "Homepage"
|
||||
assert_equal "pages/page", attachable.to_trix_content_attachment_partial_path
|
||||
|
|
Loading…
Reference in New Issue