aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-09-20 17:16:19 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2018-09-20 17:16:19 -0700
commitd14f54b0e085128b5305c806a4fe01f07b97b8fa (patch)
treeb7b9c0772ad800f9074f7440aee5d9c00dc4431e /test
parent2d6c79413d01f48df11ef76e65ba45673dcf580c (diff)
downloadrails-d14f54b0e085128b5305c806a4fe01f07b97b8fa.tar.gz
rails-d14f54b0e085128b5305c806a4fe01f07b97b8fa.tar.bz2
rails-d14f54b0e085128b5305c806a4fe01f07b97b8fa.zip
Expand router with real routing object and 4-way address options
Diffstat (limited to 'test')
-rw-r--r--test/unit/router_test.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/unit/router_test.rb b/test/unit/router_test.rb
index 8cc7bd8810..25a2651bb6 100644
--- a/test/unit/router_test.rb
+++ b/test/unit/router_test.rb
@@ -13,6 +13,12 @@ end
class SecondMailbox < RootMailbox
end
+class FirstMailboxAddress
+ def match?(inbound_email)
+ inbound_email.mail.to.include?("replies-class@example.com")
+ end
+end
+
module ActionMailroom
class RouterTest < ActiveSupport::TestCase
setup do
@@ -42,5 +48,42 @@ module ActionMailroom
assert_equal "SecondMailbox", $processed_by
assert_equal inbound_email.mail, $processed_mail
end
+
+ test "single regexp route" do
+ @router.add_routes(/replies-\w+@example.com/ => :first, "replies-nowhere@example.com" => :second)
+
+ inbound_email = create_inbound_email_from_mail(to: "replies-okay@example.com", subject: "This is a reply")
+ @router.route inbound_email
+ assert_equal "FirstMailbox", $processed_by
+ end
+
+ test "single proc route" do
+ @router.add_route \
+ ->(inbound_email) { inbound_email.mail.to.include?("replies-proc@example.com") },
+ to: :second
+
+ @router.route create_inbound_email_from_mail(to: "replies-proc@example.com", subject: "This is a reply")
+ assert_equal "SecondMailbox", $processed_by
+ end
+
+ test "address class route" do
+ @router.add_route FirstMailboxAddress.new, 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 "missing route" do
+ assert_raises(ActionMailroom::Router::RoutingError) do
+ inbound_email = create_inbound_email_from_mail(to: "going-nowhere@example.com", subject: "This is a reply")
+ @router.route inbound_email
+ end
+ end
+
+ test "invalid address" do
+ assert_raises(ActionMailroom::Router::Route::InvalidAddressError) do
+ @router.add_route Array.new, to: :first
+ @router.route create_inbound_email_from_mail(to: "replies-nowhere@example.com", subject: "This is a reply")
+ end
+ end
end
end