aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-09-19 17:20:09 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2018-09-19 17:20:09 -0700
commit66dacce5245f27ceecb527f9890aa120204f947a (patch)
tree4de780351c9ef4a2cc188bdd00fd9bead1da3844 /test
parent35654cdbd87f615e848921e50e5ebf17b0f618d2 (diff)
downloadrails-66dacce5245f27ceecb527f9890aa120204f947a.tar.gz
rails-66dacce5245f27ceecb527f9890aa120204f947a.tar.bz2
rails-66dacce5245f27ceecb527f9890aa120204f947a.zip
Test single and multiple string routes
Diffstat (limited to 'test')
-rw-r--r--test/unit/router_test.rb38
1 files changed, 30 insertions, 8 deletions
diff --git a/test/unit/router_test.rb b/test/unit/router_test.rb
index 3ce669025e..8cc7bd8810 100644
--- a/test/unit/router_test.rb
+++ b/test/unit/router_test.rb
@@ -1,24 +1,46 @@
require_relative '../test_helper'
-class RepliesMailbox < ActionMailroom::Mailbox
+class RootMailbox < ActionMailroom::Mailbox
def process
- $processed = mail.subject
+ $processed_by = self.class.to_s
+ $processed_mail = mail
end
end
+class FirstMailbox < RootMailbox
+end
+
+class SecondMailbox < RootMailbox
+end
+
module ActionMailroom
class RouterTest < ActiveSupport::TestCase
setup do
@router = ActionMailroom::Router.new
- @router.add_routes('replies@example.com' => :replies)
- $processed = false
+ $processed_by = $processed_mail = nil
end
- test "routed to mailbox" do
- @router.route \
- create_inbound_email_from_mail(to: "replies@example.com", subject: "This is a reply")
+ test "single string route" do
+ @router.add_routes("first@example.com" => :first)
+
+ inbound_email = create_inbound_email_from_mail(to: "first@example.com", subject: "This is a reply")
+ @router.route inbound_email
+ assert_equal "FirstMailbox", $processed_by
+ assert_equal inbound_email.mail, $processed_mail
+ end
+
+ test "multiple string routes" do
+ @router.add_routes("first@example.com" => :first, "second@example.com" => :second)
+
+ inbound_email = create_inbound_email_from_mail(to: "first@example.com", subject: "This is a reply")
+ @router.route inbound_email
+ assert_equal "FirstMailbox", $processed_by
+ assert_equal inbound_email.mail, $processed_mail
- assert_equal "This is a reply", $processed
+ inbound_email = create_inbound_email_from_mail(to: "second@example.com", subject: "This is a reply")
+ @router.route inbound_email
+ assert_equal "SecondMailbox", $processed_by
+ assert_equal inbound_email.mail, $processed_mail
end
end
end