A platform for community discussion. Free, open, simple.
FIX: Include poll options in HTML email notifications (#37812)
Régis Hanol17c414186f6e
diff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rbindex 197b576aa09..a2859fc4947 100644--- a/plugins/poll/plugin.rb+++ b/plugins/poll/plugin.rb@@ -99,7 +99,20 @@ after_initialize dofragment.css(".poll, [data-poll-name]").each do |poll|- poll.replace "<p><a href='#{post_url}'>#{I18n.t("poll.email.link_to_poll")}</a></p>"+ html = +""++ if title = poll.at_css(".poll-title")+ html << title.to_html+ end++ if container = poll.at_css(".poll-container")+ container.css("li").each { |li| li.remove_attribute("data-poll-option-id") }+ html << container.inner_html+ end++ html << "<p><a href='#{post_url}'>#{I18n.t("poll.email.link_to_poll")}</a></p>"++ poll.replace(html)endendend@@ -107,14 +120,11 @@ after_initialize doon(:reduce_excerpt) do |doc, options|post = options[:post]- replacement =- (- if post&.url.present?- "<a href='#{UrlHelper.normalized_encode(post.url)}'>#{I18n.t("poll.poll")}</a>"- else- I18n.t("poll.poll")- end- )+ if post&.url.present?+ replacement = "<a href='#{UrlHelper.normalized_encode(post.url)}'>#{I18n.t("poll.poll")}</a>"+ else+ replacement = I18n.t("poll.poll")+ enddoc.css("div.poll").each { |poll| poll.replace(replacement) }enddiff --git a/plugins/poll/spec/lib/pretty_text_spec.rb b/plugins/poll/spec/lib/pretty_text_spec.rbindex 3019a5b5d82..6fa28c08feb 100644--- a/plugins/poll/spec/lib/pretty_text_spec.rb+++ b/plugins/poll/spec/lib/pretty_text_spec.rb@@ -131,6 +131,40 @@ RSpec.describe PrettyText doexpect(onebox[:preview]).to include("<a href=\"#{post.url}\">poll</a>")end+ it "includes poll options when formatting for email" do+ post = Fabricate(:post, raw: <<~MD)+ A post with a poll++ [poll type=regular]+ * Tabs+ * Spaces+ * Whatever my cat walks on the keyboard+ [/poll]+ MD++ html = PrettyText.format_for_email(post.cooked, post)+ expect(html).to include("Tabs")+ expect(html).to include("Spaces")+ expect(html).to include("Whatever my cat walks on the keyboard")+ expect(html).to include(I18n.t("poll.email.link_to_poll"))+ end++ it "includes poll title when formatting for email" do+ post = Fabricate(:post, raw: <<~MD)+ [poll]+ # Best bug fix excuse?+ * It works on my machine+ * That is not a bug, it is a feature+ [/poll]+ MD++ html = PrettyText.format_for_email(post.cooked, post)+ expect(html).to include("Best bug fix excuse?")+ expect(html).to include("It works on my machine")+ expect(html).to include("That is not a bug, it is a feature")+ expect(html).to include(I18n.t("poll.email.link_to_poll"))+ end+it "can reduce excerpts" dopost = Fabricate(:post, raw: <<~MD)A post with a poll