diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2018-12-06 13:27:45 -0800 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2018-12-06 13:27:45 -0800 |
commit | a1d449e061d163fc0f6cb8c966d9ebf70923b665 (patch) | |
tree | e00f20fb882d68523816a38335bf9faff8ca88ea | |
parent | 70c87ea7709ad550c1feaaf7d3831e85d52c032f (diff) | |
download | rails-a1d449e061d163fc0f6cb8c966d9ebf70923b665.tar.gz rails-a1d449e061d163fc0f6cb8c966d9ebf70923b665.tar.bz2 rails-a1d449e061d163fc0f6cb8c966d9ebf70923b665.zip |
Add a :all catch-all route
-rw-r--r-- | lib/action_mailbox/router/route.rb | 6 | ||||
-rw-r--r-- | test/unit/router_test.rb | 17 |
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/action_mailbox/router/route.rb b/lib/action_mailbox/router/route.rb index 24be8d4804..5254043a67 100644 --- a/lib/action_mailbox/router/route.rb +++ b/lib/action_mailbox/router/route.rb @@ -9,6 +9,8 @@ class ActionMailbox::Router::Route def match?(inbound_email) case address + when :all + true when String inbound_email.mail.recipients.any? { |recipient| address.casecmp?(recipient) } when Regexp @@ -26,8 +28,8 @@ class ActionMailbox::Router::Route private def ensure_valid_address - unless [ String, Regexp, Proc ].any? { |klass| address.is_a?(klass) } || address.respond_to?(:match?) - raise ArgumentError, "Expected a String, Regexp, Proc, or matchable, got #{address.inspect}" + unless [ Symbol, String, Regexp, Proc ].any? { |klass| address.is_a?(klass) } || address.respond_to?(:match?) + raise ArgumentError, "Expected a Symbol, String, Regexp, Proc, or matchable, got #{address.inspect}" end end end diff --git a/test/unit/router_test.rb b/test/unit/router_test.rb index b8c187f95e..70d39ba6a1 100644 --- a/test/unit/router_test.rb +++ b/test/unit/router_test.rb @@ -103,6 +103,23 @@ module ActionMailbox assert_equal "Nested::FirstMailbox", $processed_by end + test "all as the only route" do + @router.add_route :all, to: :first + @router.route create_inbound_email_from_mail(to: "replies-class@example.com", subject: "This is a reply") + assert_equal "FirstMailbox", $processed_by + end + + test "all as the second route" do + @router.add_route FirstMailboxAddress.new, to: :first + @router.add_route :all, to: :second + + @router.route create_inbound_email_from_mail(to: "replies-class@example.com", subject: "This is a reply") + assert_equal "FirstMailbox", $processed_by + + @router.route create_inbound_email_from_mail(to: "elsewhere@example.com", subject: "This is a reply") + assert_equal "SecondMailbox", $processed_by + end + test "missing route" do assert_raises(ActionMailbox::Router::RoutingError) do inbound_email = create_inbound_email_from_mail(to: "going-nowhere@example.com", subject: "This is a reply") |