From 9f96d094a39100df53ea68b8bd6fa7fcafd96eac Mon Sep 17 00:00:00 2001 From: James Dabbs Date: Sat, 4 May 2019 10:53:08 -0700 Subject: Expose `mailbox_for` method Currently, the only exposed entry point into the ApplicationMailbox's configured routing system is to call `route`, which performs a lot of work to fully `process` inbound email. It'd be nice to have a way (e.g. in test) of checking which mailbox an email would route to without necessarily processing it yet. --- actionmailbox/test/unit/mailbox/routing_test.rb | 5 +++++ actionmailbox/test/unit/router_test.rb | 14 ++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'actionmailbox/test') diff --git a/actionmailbox/test/unit/mailbox/routing_test.rb b/actionmailbox/test/unit/mailbox/routing_test.rb index d4ba702ac5..1ae56eb707 100644 --- a/actionmailbox/test/unit/mailbox/routing_test.rb +++ b/actionmailbox/test/unit/mailbox/routing_test.rb @@ -28,4 +28,9 @@ class ActionMailbox::Base::RoutingTest < ActiveSupport::TestCase assert_equal "Discussion: Let's debate these attachments", $processed end end + + test "mailbox_for" do + mail = create_inbound_email_from_fixture "welcome.eml", status: :pending + assert_equal RepliesMailbox, ApplicationMailbox.mailbox_for(mail) + end end diff --git a/actionmailbox/test/unit/router_test.rb b/actionmailbox/test/unit/router_test.rb index c5dce60856..4dd3730604 100644 --- a/actionmailbox/test/unit/router_test.rb +++ b/actionmailbox/test/unit/router_test.rb @@ -135,5 +135,19 @@ module ActionMailbox @router.add_route Array.new, to: :first end end + + test "single string mailbox_for" do + @router.add_routes("first@example.com" => :first) + + inbound_email = create_inbound_email_from_mail(to: "first@example.com", subject: "This is a reply") + assert_equal FirstMailbox, @router.mailbox_for(inbound_email) + end + + test "mailbox_for with no matches" do + @router.add_routes("first@example.com" => :first) + + inbound_email = create_inbound_email_from_mail(to: "second@example.com", subject: "This is a reply") + assert_nil @router.mailbox_for(inbound_email) + end end end -- cgit v1.2.3