From 9313706649176fd60989116dc4248be76d7d34c1 Mon Sep 17 00:00:00 2001 From: Daniel Waterworth Date: Mon, 20 Jul 2020 10:04:04 +0100 Subject: [PATCH] DEV: Enable preserve_email_structure_when_styling by default In 1bd8a075, a hidden site setting was added that causes Email::Styles to treat its input as a complete document in all cases. This commit enables that setting by default. Some tests were removed that were broken by this change. They tested the behaviour of applying email styles to empty strings. They weren't useful because: * Sending empty email is not something we ever intend to do, * They were testing incidental behaviour - there are lots of valid ways to process the empty string, * Their intent wasn't clear from their descriptions, --- config/site_settings.yml | 2 +- spec/components/email/styles_spec.rb | 15 +-------------- spec/integration/email_style_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/config/site_settings.yml b/config/site_settings.yml index 03c0d951f09..714fa88b7a0 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -1131,7 +1131,7 @@ email: default: true hidden: true preserve_email_structure_when_styling: - default: false + default: true hidden: true files: diff --git a/spec/components/email/styles_spec.rb b/spec/components/email/styles_spec.rb index 74addfe29dd..c53d56da888 100644 --- a/spec/components/email/styles_spec.rb +++ b/spec/components/email/styles_spec.rb @@ -19,13 +19,6 @@ describe Email::Styles do end context "basic formatter" do - - it "works with an empty string" do - style = Email::Styles.new("") - style.format_basic - expect(style.to_html).to be_blank - end - it "adds a max-width to large images" do frag = basic_fragment("") expect(frag.at("img")["style"]).to match("max-width") @@ -56,12 +49,6 @@ describe Email::Styles do end context "html template formatter" do - it "works with an empty string" do - style = Email::Styles.new("") - style.format_html - expect(style.to_html).to be_blank - end - it "attaches a style to h3 tags" do frag = html_fragment("

hello

") expect(frag.at('h3')['style']).to be_present @@ -188,7 +175,7 @@ describe Email::Styles do cooked = "Create a method for click on image and use ng-click in in your slide box...it is simple" style = Email::Styles.new(cooked) style.strip_avatars_and_emojis - expect(style.to_html).to eq(cooked) + expect(style.to_html).to include(cooked) end end diff --git a/spec/integration/email_style_spec.rb b/spec/integration/email_style_spec.rb index f0844dbd32a..f4df68333b6 100644 --- a/spec/integration/email_style_spec.rb +++ b/spec/integration/email_style_spec.rb @@ -8,8 +8,8 @@ describe EmailStyle do it "does not evaluate ERB outside of the email itself" do SiteSetting.email_custom_template = "%{email_content}<%= (111 * 333) %>" html = Email::Renderer.new(UserNotifications.signup(Fabricate(:user))).html - expect(html).not_to match("36963") - expect(html.starts_with?('')).to eq(true) + expect(html).not_to include("36963") + expect(html).to include('') end end