Skip to content

A platform for community discussion. Free, open, simple.

FIX: use digest_min_excerpt_length site setting in summary emails

Neil Lalonde34a0e79bec39
diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb
index 2e18c702ee3..de7826586fb 100644
--- a/app/helpers/user_notifications_helper.rb
+++ b/app/helpers/user_notifications_helper.rb
@@ -39,7 +39,7 @@ module UserNotificationsHelper
doc.css('body > p, aside.onebox').each do |node|
if node.text.present?
result << node.to_s
- return result if result.size >= 100
+ return result if result.size >= SiteSetting.digest_min_excerpt_length
end
end
return result unless result.blank?
@@ -48,9 +48,8 @@ module UserNotificationsHelper
doc.css('div').first
end
- def email_excerpt(html_arg, posts_count = nil)
- # only include 1st paragraph when more than 1 posts
- html = (posts_count.nil? || posts_count > 1) ? (first_paragraph_from(html_arg) || html_arg).to_s : html_arg
+ def email_excerpt(html_arg)
+ html = (first_paragraph_from(html_arg) || html_arg).to_s
PrettyText.format_for_email(html).html_safe
end
diff --git a/spec/helpers/user_notifications_helper_spec.rb b/spec/helpers/user_notifications_helper_spec.rb
new file mode 100644
index 00000000000..191f4a984a8
--- /dev/null
+++ b/spec/helpers/user_notifications_helper_spec.rb
@@ -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