Merge pull request #888 from basecamp/flavorjones/fix-excerpts

Fix Excerpt Helper which was blocking some mention notifications from getting sent
This commit is contained in:
Mike Dalessio
2025-08-11 17:41:18 -04:00
committed by GitHub
2 changed files with 33 additions and 2 deletions
+2 -2
View File
@@ -2,9 +2,9 @@ module ExcerptHelper
def format_excerpt(content, length: 200)
return "" if content.blank?
text = content.to_plain_text
text = content.respond_to?(:to_plain_text) ? content.to_plain_text : content.to_s
text = text.gsub(/^>\s*(.*)$/m, '> \1')
text = text.gsub(/^[-*]\s*(.*)$/m, '• \1')
text = text.gsub(/^\s*[-+]\s*(.*)$/m, '• \1')
text = text.gsub(/^\d+\.\s*(.*)$/m) { |m| m }
text = text.gsub(/\s+/, " ").strip
text.truncate(length)
+31
View File
@@ -0,0 +1,31 @@
require "test_helper"
class ExcerptHelperTest < ActionView::TestCase
test "quote" do
assert_excerpt("> Hello world", "> Hello world")
end
test "ul" do
assert_excerpt("• Hello world", "- Hello world")
assert_excerpt("• Hello world", " - Hello world")
end
test "ol" do
assert_excerpt("99. Hello world", "99. Hello world")
end
test "large spaces" do
assert_excerpt("Hello world", " Hello world ")
end
test "long text" do
assert_excerpt("A"*197 + "...", "A"*1000)
assert_excerpt("A"*97 + "...", "A"*1000, length: 100)
end
private
def assert_excerpt(expected, content, ...)
assert_equal expected, format_excerpt(ActionText::Content.new(content), ...), "Excerpt of Action Text Content does not match"
assert_equal expected, format_excerpt(content, ...), "Excerpt of String does not match"
end
end