FIX: use digest_min_excerpt_length site setting in summary emails

This commit is contained in:
Neil Lalonde 2018-03-08 17:59:33 -05:00
parent 2f54eab9a6
commit 34a0e79bec
2 changed files with 27 additions and 4 deletions

View File

@ -39,7 +39,7 @@ module UserNotificationsHelper
doc.css('body > p, aside.onebox').each do |node| doc.css('body > p, aside.onebox').each do |node|
if node.text.present? if node.text.present?
result << node.to_s result << node.to_s
return result if result.size >= 100 return result if result.size >= SiteSetting.digest_min_excerpt_length
end end
end end
return result unless result.blank? return result unless result.blank?
@ -48,9 +48,8 @@ module UserNotificationsHelper
doc.css('div').first doc.css('div').first
end end
def email_excerpt(html_arg, posts_count = nil) def email_excerpt(html_arg)
# only include 1st paragraph when more than 1 posts html = (first_paragraph_from(html_arg) || html_arg).to_s
html = (posts_count.nil? || posts_count > 1) ? (first_paragraph_from(html_arg) || html_arg).to_s : html_arg
PrettyText.format_for_email(html).html_safe PrettyText.format_for_email(html).html_safe
end end

View File

@ -0,0 +1,24 @@
require 'rails_helper'
describe UserNotificationsHelper do
describe 'email_excerpt' do
let(:paragraphs) { [
"<p>This is the first paragraph, but you should read more.</p>",
"<p>And here is its friend, the second paragraph.</p>"
] }
let(:cooked) do
paragraphs.join("\n")
end
it "can return the first paragraph" do
SiteSetting.digest_min_excerpt_length = 50
expect(helper.email_excerpt(cooked)).to eq(paragraphs[0])
end
it "can return another paragraph to satisfy digest_min_excerpt_length" do
SiteSetting.digest_min_excerpt_length = 100
expect(helper.email_excerpt(cooked)).to eq(paragraphs.join)
end
end
end