Files
eminuxCRM/test/mailers/campaign_mailer_test.rb
T
eminuxandCursor c4e5f289cf
CI / scan_ruby (push) Failing after 11m20s
CI / scan_js (push) Successful in 10m35s
CI / lint (push) Has been cancelled
Commit iniziale di eminuxCRM: CRM Rails con pipeline, campagne email e Docker.
Include autenticazione, progetti isolati, mail marketing HTML con SMTP, test A/B e editor WYSIWYG.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-17 23:01:48 +02:00

48 lines
1.9 KiB
Ruby

require "test_helper"
require "base64"
class CampaignMailerTest < ActionMailer::TestCase
test "sends html with merge and attachments from the identity" do
mailing = create_mailing
mailing.rebuild_recipients!
mailing.files.attach(io: StringIO.new("brochure"), filename: "brochure.pdf", content_type: "application/pdf")
recipient = mailing.mailing_recipients.first
email = CampaignMailer.outreach(
recipient,
html: recipient.rendered_html,
subject: recipient.rendered_subject_line
)
assert_emails 1 do
email.deliver_now
end
assert_equal ["hello@example.com"], email.from
assert_equal ["mario@asdtest.example.it"], email.to
assert_equal "Ciao ASD Test Calcio", email.subject
body = (email.html_part || email).body.to_s
assert_match(/Ciao Mario Rossi di ASD Test Calcio/, body)
assert_equal 1, email.attachments.size
assert_equal "brochure.pdf", email.attachments.first.filename
end
test "inlines active storage images as cid attachments" do
png = Base64.decode64("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==")
blob = ActiveStorage::Blob.create_and_upload!(io: StringIO.new(png), filename: "pixel.png", content_type: "image/png")
src = Rails.application.routes.url_helpers.rails_blob_path(blob, only_path: true)
mailing = create_mailing(body_html: %(<p>Foto</p><figure><img src="#{src}" width="240" height="120"></figure>))
mailing.rebuild_recipients!
recipient = mailing.mailing_recipients.first
email = CampaignMailer.outreach(recipient, html: recipient.rendered_html, subject: "Foto")
email.deliver_now
assert email.attachments.any? { |att| att.filename.to_s.include?("pixel.png") }
body = (email.html_part || email).body.to_s
assert_match(/cid:/, body)
assert_match(/width:\s*240px/, body)
assert_no_match(/<figure/, body)
end
end