diff options
-rw-r--r-- | actionmailbox/CHANGELOG.md | 2 | ||||
-rw-r--r-- | actionmailbox/lib/action_mailbox/router.rb | 10 | ||||
-rw-r--r-- | actionmailbox/lib/action_mailbox/routing.rb | 4 | ||||
-rw-r--r-- | actionmailbox/test/unit/mailbox/routing_test.rb | 5 | ||||
-rw-r--r-- | actionmailbox/test/unit/router_test.rb | 14 | ||||
-rw-r--r-- | guides/source/upgrading_ruby_on_rails.md | 6 |
6 files changed, 33 insertions, 8 deletions
diff --git a/actionmailbox/CHANGELOG.md b/actionmailbox/CHANGELOG.md index a86adae5a7..605a38b06b 100644 --- a/actionmailbox/CHANGELOG.md +++ b/actionmailbox/CHANGELOG.md @@ -1,3 +1,5 @@ +* Add `ApplicationMailbox.mailbox_for` to expose mailbox routing. + *James Dabbs* Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/actionmailbox/CHANGELOG.md) for previous changes. diff --git a/actionmailbox/lib/action_mailbox/router.rb b/actionmailbox/lib/action_mailbox/router.rb index 71370e409d..54982eae21 100644 --- a/actionmailbox/lib/action_mailbox/router.rb +++ b/actionmailbox/lib/action_mailbox/router.rb @@ -21,7 +21,7 @@ module ActionMailbox end def route(inbound_email) - if mailbox = match_to_mailbox(inbound_email) + if mailbox = mailbox_for(inbound_email) mailbox.receive(inbound_email) else inbound_email.bounced! @@ -30,12 +30,12 @@ module ActionMailbox end end + def mailbox_for(inbound_email) + routes.detect { |route| route.match?(inbound_email) }.try(:mailbox_class) + end + private attr_reader :routes - - def match_to_mailbox(inbound_email) - routes.detect { |route| route.match?(inbound_email) }.try(:mailbox_class) - end end end diff --git a/actionmailbox/lib/action_mailbox/routing.rb b/actionmailbox/lib/action_mailbox/routing.rb index 58462a44c6..8391bf9db0 100644 --- a/actionmailbox/lib/action_mailbox/routing.rb +++ b/actionmailbox/lib/action_mailbox/routing.rb @@ -17,6 +17,10 @@ module ActionMailbox def route(inbound_email) router.route(inbound_email) end + + def mailbox_for(inbound_email) + router.mailbox_for(inbound_email) + end end end end diff --git a/actionmailbox/test/unit/mailbox/routing_test.rb b/actionmailbox/test/unit/mailbox/routing_test.rb index d4ba702ac5..8302b1d5cc 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 + inbound_email = create_inbound_email_from_fixture "welcome.eml", status: :pending + assert_equal RepliesMailbox, ApplicationMailbox.mailbox_for(inbound_email) + 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 diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 5bd4b06274..290aabc6f9 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -140,7 +140,7 @@ The default configuration for Rails 6 ```ruby # config/application.rb -load_defaults "6.0" +config.load_defaults "6.0" ``` enables `zeitwerk` autoloading mode on CRuby. In that mode, autoloading, reloading, and eager loading are managed by [Zeitwerk](https://github.com/fxn/zeitwerk). @@ -166,7 +166,7 @@ However, `classic` mode infers file names from missing constant names (`undersco ```ruby # config/application.rb -load_defaults "6.0" +config.load_defaults "6.0" config.autoloader = :classic ``` @@ -346,7 +346,7 @@ Applications can load Rails 6 defaults and still use the classic autoloader by s ```ruby # config/application.rb -load_defaults "6.0" +config.load_defaults "6.0" config.autoloader = :classic ``` |