Rebuild every attachment before editing a message

The editor keeps an attachment's content as it finds it, so a hand-written
embed with a url but no href reached the editor with its markup unvalidated,
and a mention saved under Trix's editor carried the generic octet-stream
content type the editor doesn't permit and was dropped on save. Rebuilding
each attachment from its attachable renders the hardened preview partial
and restores the mention content type.
This commit is contained in:
Stanko K.R.
2026-09-26 09:51:05 +02:00
parent eab554aa4b
commit 6acad0549d
5 changed files with 81 additions and 10 deletions
+28
View File
@@ -86,6 +86,34 @@ class ComposerTest < ApplicationSystemTestCase
assert_equal [ users(:jason) ], message.reload.mentionees
end
test "editing a message whose mention was saved under Trix keeps the mention" do
body = %(<div>Hey <action-text-attachment sgid="#{users(:jason).attachable_sgid}" content-type="application/octet-stream"></action-text-attachment></div>)
message = Message.create! room: rooms(:designers), body: body, client_message_id: "trix-edited", creator: users(:jz)
join_room rooms(:designers)
within_message message do
reveal_message_actions
find(".message__edit-btn").click
assert_edit_editor_text "Jason"
click_on "Save changes"
end
assert_selector last_message_selector(".mention"), text: "Jason"
assert_equal [ users(:jason) ], message.reload.mentionees
end
test "pasting a table keeps its text" do
paste_in_composer "Name Points\nJason 10", html: "<table><tr><th>Name</th><th>Points</th></tr><tr><td>Jason</td><td>10</td></tr></table>"
assert_selector "#composer lexxy-editor table"
click_send_button
assert_message_text /Name Points\s*Jason 10/
assert_no_selector last_message_selector("table")
end
test "replying quotes the original message with attribution" do
within_message messages(:third) do
reveal_message_actions