A platform for community discussion. Free, open, simple.
FIX: email excerpts for posts starting with a quote were displaying a username
Neil Lalonde565a96719277
diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rbindex d7e619f0298..0df7aa6926c 100644--- a/app/helpers/user_notifications_helper.rb+++ b/app/helpers/user_notifications_helper.rb@@ -47,8 +47,9 @@ module UserNotificationsHelperreturn result unless result.blank?- # If there is no first paragaph, return the first div (onebox)- doc.css('div').first+ # If there is no first paragaph with text, return the first paragraph with+ # something else (an image) or div (a onebox).+ doc.css('body > p, body > div').firstenddef email_excerpt(html_arg, post = nil)diff --git a/spec/helpers/user_notifications_helper_spec.rb b/spec/helpers/user_notifications_helper_spec.rbindex a0d266e2b10..7610495b258 100644--- a/spec/helpers/user_notifications_helper_spec.rb+++ b/spec/helpers/user_notifications_helper_spec.rb@@ -13,6 +13,19 @@ describe UserNotificationsHelper doparagraphs.join("\n")end+ let(:post_quote) do+ <<~HTML+ <aside class="quote no-group" data-post="859" data-topic="30">+ <div class="title">+ <div class="quote-controls"></div>+ <img alt width="20" height="20" src="https://example.com/m.png" class="avatar"> modman:</div>+ <blockquote>+ <p>This is a post quote</p>+ </blockquote>+ </aside>+ HTML+ end+it "can return the first paragraph" doSiteSetting.digest_min_excerpt_length = 50expect(helper.email_excerpt(cooked)).to eq(paragraphs[0])@@ -54,6 +67,24 @@ describe UserNotificationsHelper doexpect(helper.email_excerpt(cooked)).to eq "<p>BEFORE</p><blockquote>\n <p>This is a user quote</p>\n</blockquote><p>AFTER</p>"end++ it "defaults to content after post quote (image w/ no text)" do+ image_paragraph = '<p><img src="//localhost:3000/uploads/b9.png" width="300" height="300"></p>'+ cooked = <<~HTML+ #{post_quote}+ #{image_paragraph}+ HTML+ expect(helper.email_excerpt(cooked)).to eq(image_paragraph)+ end++ it "defaults to content after post quote (onebox)" do+ aside_onebox = '<aside class="onebox wikipedia"><article class="onebox-body"><p>Onebox excerpt here</p></article><div class="onebox-metadata"></div></aside>'+ cooked = <<~HTML+ #{post_quote}+ #{aside_onebox}+ HTML+ expect(helper.email_excerpt(cooked)).to eq(aside_onebox)+ endenddescribe '#logo_url' do