1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
# frozen_string_literal: true
require "spec_helper"
require "mail"
module Roadie
module Rails
describe MailInliner do
let(:email) { Mail.new }
let(:options) { Options.new }
subject(:inliner) { MailInliner.new(email, options) }
it "takes an email and options" do
inliner = MailInliner.new(email, options)
expect(inliner.email).to eq(email)
expect(inliner.options).to eq(options)
end
context "with an plaintext email" do
let(:email) do
Mail.new do
body "Hello world"
end
end
it "returns the email without doing anything" do
expect(inliner.execute).to eq(email)
expect(email.html_part).to be_nil
expect(email.body.decoded).to eq("Hello world")
end
it "does nothing when given nil options" do
inliner = MailInliner.new(email, nil)
expect { inliner.execute }.to_not raise_error
end
end
context "with an HTML email" do
let(:html) { "<h1>Hello world!</h1>" }
let(:email) do
html_string = html
Mail.new do
content_type "text/html; charset=UTF-8"
body html_string
end
end
it "adjusts the html part using Roadie" do
document = double "A document", transform: "transformed HTML"
allow(DocumentBuilder).to receive(:build).and_return(document)
inliner.execute
expect(email.body.decoded).to eq("transformed HTML")
expect(DocumentBuilder).to have_received(:build).with(
html,
instance_of(Options)
)
end
it "does nothing when given nil options" do
inliner = MailInliner.new(email, nil)
expect { inliner.execute }.to_not raise_error
end
end
context "with an multipart email" do
let(:html) { "<h1>Hello world!</h1>" }
let(:email) do
html_string = html
Mail.new do
text_part { body "Hello world" }
html_part { body html_string }
end
end
it "returns the email" do
expect(inliner.execute).to eq(email)
end
it "adjusts the html part using Roadie" do
document = double "A document", transform: "transformed HTML"
allow(DocumentBuilder).to receive(:build).and_return(document)
inliner.execute
expect(email.html_part.body.decoded).to eq("transformed HTML")
expect(DocumentBuilder).to have_received(:build).with(
html,
instance_of(Options)
)
end
it "does nothing when given nil options" do
inliner = MailInliner.new(email, nil)
expect { inliner.execute }.to_not raise_error
end
end
end
end
end
|