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) recipient.reload assert_match(%r{/t/o/#{Regexp.escape(recipient.tracking_token)}\.gif}, 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: %(
Foto