From 40d63cee31a99e57c05d86cab12507b535af135f Mon Sep 17 00:00:00 2001 From: Paul McMahon Date: Mon, 2 Dec 2019 11:03:55 +0900 Subject: [PATCH] Test extensions to Mail gem The from_address method is added to Mail::Message, but is not used internally to ActionMailbox, nor tested (even implicitly). As it is part of the public API, it feels important to at least have a basic test of it. Similarly, the x_original_to_addresses was only implicitly tested via the recipients_addresses method. Given other similar methods are explicitly tested, it feels like an oversight not to test it as well. As the test introduced from_address didn't align with the naming of RecipientsTest, I renamed it to the more generic AddressesTest. --- .../{recipients_test.rb => addresses_test.rb} | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) rename actionmailbox/test/unit/mail_ext/{recipients_test.rb => addresses_test.rb} (74%) diff --git a/actionmailbox/test/unit/mail_ext/recipients_test.rb b/actionmailbox/test/unit/mail_ext/addresses_test.rb similarity index 74% rename from actionmailbox/test/unit/mail_ext/recipients_test.rb rename to actionmailbox/test/unit/mail_ext/addresses_test.rb index fdcad440e2..0758921d26 100644 --- a/actionmailbox/test/unit/mail_ext/recipients_test.rb +++ b/actionmailbox/test/unit/mail_ext/addresses_test.rb @@ -3,15 +3,20 @@ require_relative "../../test_helper" module MailExt - class RecipientsTest < ActiveSupport::TestCase + class AddressesTest < ActiveSupport::TestCase setup do @mail = Mail.new \ + from: "sally@example.com", to: "david@basecamp.com", cc: "jason@basecamp.com", bcc: "andrea@basecamp.com", x_original_to: "ryan@basecamp.com" end + test "from address uses address object" do + assert_equal "example.com", @mail.from_address.domain + end + test "recipients include everyone from to, cc, bcc, and x-original-to" do assert_equal %w[ david@basecamp.com jason@basecamp.com andrea@basecamp.com ryan@basecamp.com ], @mail.recipients end @@ -31,5 +36,9 @@ module MailExt test "bcc addresses use address objects" do assert_equal "basecamp.com", @mail.bcc_addresses.first.domain end + + test "x_original_to addresses use address objects" do + assert_equal "basecamp.com", @mail.x_original_to_addresses.first.domain + end end end