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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
# frozen_string_literal: true
require "spec_helper"
require "tempfile"
require "mail"
require "bundler"
describe "Integrations" do
def parse_html_in_email(mail)
Nokogiri::HTML.parse mail.html_part.body.decoded
end
rails_apps = [
#RailsApp.new("Rails 5.1", "rails_51", max_ruby_version: "2.7"),
#RailsApp.new("Rails 5.2", "rails_52", max_ruby_version: "2.7"),
#RailsApp.new("Rails 6.0", "rails_60", max_ruby_version: "3.0"),
#RailsApp.new("Rails 6.1", "rails_61", max_ruby_version: "3.0"),
#RailsApp.new("Rails 7.0", "rails_70", min_ruby_version: "2.7"),
#RailsApp.new("Rails 7.1 with sprockets", "rails_71", min_ruby_version: "2.7"),
#RailsApp.new("Rails 7.1 with propshaft", "rails_71_with_propshaft", min_ruby_version: "2.7",
# asset_pipeline: :propshaft),
#RailsApp.new("Rails 8.0 with propshaft", "rails_80_with_propshaft", min_ruby_version: "3.2",
# asset_pipeline: :propshaft),
]
shared_examples "generates valid email" do |message|
it "inlines styles #{message}" do
expect(email.to).to eq(["example@example.org"])
expect(email.from).to eq(["john@example.com"])
expect(email).to have(2).parts
expect(email.text_part.body.decoded).not_to match(/<.*>/)
html = email.html_part.body.decoded
expect(html).to include "<!DOCTYPE"
expect(html).to include "<head"
document = parse_html_in_email(email)
expect(document).to have_selector("body h1")
expected_image_url =
"https://example.app.org/assets/rails-cd95a25e70dfe61add5a96e11d3fee0f29e9ba2b05099723d57bba7dfa725c8a.png"
expect(document).to have_styling(
"background" => "url(#{expected_image_url})"
).at_selector(".image")
# If we deliver mails we can catch weird problems with headers being
# invalid
email.delivery_method :test
email.deliver
end
end
rails_apps.select(&:supported?).select(&:with_sprockets?).each do |app|
describe "with #{app}" do
before { app.reset }
include_examples "generates valid email", "for multipart emails" do
let(:email) { app.read_email(:normal_email) }
end
include_examples "generates valid email", "with automatic mailer" do
let(:email) { app.read_delivered_email(:normal_email) }
end
include_examples(
"generates valid email",
"with automatic mailer and forced delivery"
) do
let(:email) do
app.read_delivered_email(:normal_email, force_delivery: true)
end
end
it "inlines no styles when roadie_options are nil" do
email = app.read_delivered_email(:disabled_email)
expect(email.to).to eq(["example@example.org"])
expect(email.from).to eq(["john@example.com"])
expect(email).to have(2).parts
document = parse_html_in_email(email)
expect(document).to have_no_styling.at_selector(".image")
# If we deliver mails we can catch weird problems with headers being
# invalid
email.delivery_method :test
email.deliver
end
it "has a AssetPipelineProvider together with a FilesystemProvider" do
expect(app.read_providers).to eq(
%w[
Roadie::FilesystemProvider
Roadie::Rails::AssetPipelineProvider
]
)
end
end
end
rails_apps.select(&:supported?).select(&:with_propshaft?).each do |app|
describe "with #{app}" do
before { app.reset }
it "inlines styles for multipart emails" do
email = app.read_email(:normal_email)
expect(email.to).to eq(["example@example.org"])
expect(email.from).to eq(["john@example.com"])
expect(email).to have(2).parts
expect(email.text_part.body.decoded).not_to match(/<.*>/)
html = email.html_part.body.decoded
expect(html).to include "<!DOCTYPE"
expect(html).to include "<head"
document = parse_html_in_email(email)
expect(document).to have_selector("body h1")
expect(document).to have_styling(
"background-color" => "green"
).at_selector("body")
expected_image_url =
"https://example.app.org/assets/rails-fbe4356d.png"
expect(document).to have_styling(
"background" => "url(\"#{expected_image_url}\")"
).at_selector(".image")
# If we deliver mails we can catch weird problems with headers being
# invalid
email.delivery_method :test
email.deliver
end
it "inlines styles with automatic mailer" do
email = app.read_delivered_email(:normal_email)
expect(email.to).to eq(["example@example.org"])
expect(email.from).to eq(["john@example.com"])
expect(email).to have(2).parts
expect(email.text_part.body.decoded).not_to match(/<.*>/)
html = email.html_part.body.decoded
expect(html).to include "<!DOCTYPE"
expect(html).to include "<head"
document = parse_html_in_email(email)
expect(document).to have_selector("body h1")
expect(document).to have_styling(
"background-color" => "green"
).at_selector("body")
expected_image_url =
"https://example.app.org/assets/rails-fbe4356d.png"
expect(document).to have_styling(
"background" => "url(\"#{expected_image_url}\")"
).at_selector(".image")
# If we deliver mails we can catch weird problems with headers being
# invalid
email.delivery_method :test
email.deliver
end
it "has a AssetPropshaftProvider together with a FilesystemProvider" do
expect(app.read_providers).to eq(
%w[
Roadie::FilesystemProvider
Roadie::Rails::AssetPropshaftProvider
]
)
end
end
end
end
|