FIX: add excerpt fallback for chat message replies (#26834)

This commit is contained in:
David Battersby 2024-05-01 22:39:47 +08:00 committed by GitHub
parent acdaa3b579
commit c1f6ec5f62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View File

@ -10,5 +10,9 @@ module Chat
def user
object.user || Chat::NullUser.new
end
def excerpt
object.excerpt || object.build_excerpt
end
end
end

View File

@ -30,5 +30,10 @@ RSpec.describe Chat::InReplyToSerializer do
it "censors words" do
expect(serializer.as_json[:excerpt]).to eq("ok ■■■■■")
end
it "builds an excerpt for replied to message if it doesnt have one" do
message.update!(excerpt: nil)
expect(serializer.as_json[:excerpt]).to eq(message.build_excerpt)
end
end
end