2019-07-30 15:05:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe EmailStyleUpdater do
|
2019-07-30 15:05:08 -04:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
|
|
let(:default_html) { File.read("#{Rails.root}/app/views/email/default_template.html") }
|
|
|
|
let(:updater) { EmailStyleUpdater.new(admin) }
|
|
|
|
|
2019-10-23 15:41:58 -04:00
|
|
|
def expect_settings_to_be_unset
|
|
|
|
expect(SiteSetting.email_custom_template).to_not be_present
|
|
|
|
expect(SiteSetting.email_custom_css).to_not be_present
|
|
|
|
expect(SiteSetting.email_custom_css_compiled).to_not be_present
|
|
|
|
end
|
|
|
|
|
2019-07-30 15:05:08 -04:00
|
|
|
describe "update" do
|
|
|
|
it "can change the settings" do
|
|
|
|
expect(updater.update(html: "For you: %{email_content}", css: "h1 { color: blue; }")).to eq(
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
expect(SiteSetting.email_custom_template).to eq("For you: %{email_content}")
|
|
|
|
expect(SiteSetting.email_custom_css).to eq("h1 { color: blue; }")
|
2019-10-23 15:41:58 -04:00
|
|
|
expect(SiteSetting.email_custom_css_compiled.strip).to eq("h1{color:blue}")
|
2019-07-30 15:05:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "will not store defaults" do
|
|
|
|
updater.update(html: default_html, css: "")
|
2019-10-23 15:41:58 -04:00
|
|
|
expect_settings_to_be_unset
|
2019-07-30 15:05:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can clear settings if defaults given" do
|
|
|
|
SiteSetting.email_custom_template = "For you: %{email_content}"
|
|
|
|
SiteSetting.email_custom_css = "h1 { color: blue; }"
|
2019-10-23 15:41:58 -04:00
|
|
|
SiteSetting.email_custom_css_compiled = "h1{color:blue}"
|
2019-07-30 15:05:08 -04:00
|
|
|
updater.update(html: default_html, css: "")
|
2019-10-23 15:41:58 -04:00
|
|
|
expect_settings_to_be_unset
|
2019-07-30 15:05:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if html is missing email_content" do
|
|
|
|
expect(updater.update(html: "No email content", css: "")).to eq(false)
|
|
|
|
expect(updater.errors).to include(
|
|
|
|
I18n.t("email_style.html_missing_placeholder", placeholder: "%{email_content}"),
|
|
|
|
)
|
2019-10-23 15:41:58 -04:00
|
|
|
expect_settings_to_be_unset
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if css is not valid scss" do
|
|
|
|
expect(updater.update(html: "For you: %{email_content}", css: "h1 { color: blue;")).to eq(
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
expect(updater.errors).to_not be_empty
|
2023-02-07 10:24:57 -05:00
|
|
|
expect(updater.errors.first).to include('Error: expected "}".')
|
2019-10-23 15:41:58 -04:00
|
|
|
expect_settings_to_be_unset
|
2019-07-30 15:05:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|