discourse/spec/lib/email/renderer_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "email/renderer"
RSpec.describe Email::Renderer do
let(:message) do
mail = Mail.new
mail.text_part = Mail::Part.new { body "Key & Peele" }
mail.html_part =
Mail::Part.new do
content_type "text/html; charset=UTF-8"
body "<h1>Key &amp; Peele</h1> <a href=\"https://discourse.org\">Discourse link</a>"
end
mail
end
let(:renderer) { Email::Renderer.new(message) }
it "escapes HTML entities from text" do
2015-01-10 00:34:37 +08:00
expect(renderer.text).to eq("Key & Peele")
end
context "with email_renderer_html modifier" do
after { DiscoursePluginRegistry.reset! }
it "can modify the html" do
Plugin::Instance
.new
.register_modifier(:email_renderer_html) do |styles, _|
styles.fragment.css("a").each { |link| link["href"] = "httpz://hijacked.sorry" }
end
expect(renderer.html).not_to include("href=\"https://discourse.org\"")
expect(renderer.html).to include("href=\"httpz://hijacked.sorry\"")
end
end
end