Testing Devise Mailer Configuration and Content Handling in heartcombo/devise
This test suite validates the Devise mailer functionality, focusing on email configuration and content handling. It ensures proper behavior of mail delivery options and default value processing in the authentication system.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
heartcombo/devise
test/mailers/mailer_test.rb
# frozen_string_literal: true
require "test_helper"
class MailerTest < ActionMailer::TestCase
test "pass given block to #mail call" do
class TestMailer < Devise::Mailer
def confirmation_instructions(record, token, opts = {})
@token = token
devise_mail(record, :confirmation_instructions, opts) do |format|
format.html(content_transfer_encoding: "7bit")
end
end
end
mail = TestMailer.confirmation_instructions(create_user, "confirmation-token")
assert mail.content_transfer_encoding, "7bit"
end
test "default values defined as proc with different arity are handled correctly" do
class TestMailerWithDefault < Devise::Mailer
default from: -> { computed_from }
default reply_to: ->(_) { computed_reply_to }
def confirmation_instructions(record, token, opts = {})
@token = token
devise_mail(record, :confirmation_instructions, opts)
end
private
def computed_from
"[email protected]"
end
def computed_reply_to
"[email protected]"
end
end
mail = TestMailerWithDefault.confirmation_instructions(create_user, "confirmation-token")
assert mail.from, "[email protected]"
assert mail.reply_to, "[email protected]"
end
end