]> git.openstreetmap.org Git - rails.git/commit
Avoid showing very long pieces of text in notifications
authorPablo Brasero <pablo@pablobm.com>
Tue, 14 Jul 2026 17:23:00 +0000 (18:23 +0100)
committerPablo Brasero <pablo@pablobm.com>
Tue, 4 Aug 2026 11:28:03 +0000 (12:28 +0100)
commit620cd0f56e51f46e943f5a6a5b0cd915eba108a6
tree800333d8e0c46eddacc34c9eaf70ab5a29a2fa31
parent2bde4911ce4f47712579a5f51b3c0ea626b47ff1
Avoid showing very long pieces of text in notifications

I am unsure about this one. I am relying on `RichText#truncate_html`, to avoid having to put together my own truncation facility. My problem is that I find that method to be too coarse-grained as it works by removing entire HTML elements:

- If the text starts with a small paragraph, then a long one, it may only show the first.
- If it starts with a long paragraph, it may not show anything, or it will show the whole paragraph.

I think this is confusing. Note that can't just use Rails's own `String#truncate` as this is a `RichText`, not a `String`, and then we'd have to worry about truncating the HTML.

Having said that: `#truncate_html` is right there, and it is what we use for diary entries. So I guess let's reuse it, leaving it for a future contribution to rework it into something better, if there's inclination.
app/views/notifications/_changeset_comment.html.erb
app/views/notifications/_diary_comment.html.erb
app/views/notifications/_note_comment.html.erb
app/views/notifications/_notification_quote.html.erb
test/controllers/notifications/changeset_comment_view_test.rb
test/controllers/notifications/diary_comment_view_test.rb
test/controllers/notifications/note_comment_view_test.rb
test/fixtures/lorem_ipsum.txt [new file with mode: 0644]
test/test_helper.rb