Skip to content

Commit 7300e06

Browse files
committed
Use mailbox_for when available
rails/rails#36181
1 parent ff94e1b commit 7300e06

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/rspec/rails/matchers/action_mailbox.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,20 @@ def initialize(message)
2222
@inbound_email = create_inbound_email(message)
2323
end
2424

25-
def matches?(mailbox)
26-
@mailbox = mailbox
27-
@receiver = ApplicationMailbox.router.send(:match_to_mailbox, inbound_email)
25+
if defined?(::ApplicationMailbox) && ::ApplicationMailbox.router.respond_to?(:mailbox_for)
26+
def matches?(mailbox)
27+
@mailbox = mailbox
28+
@receiver = ApplicationMailbox.router.mailbox_for(inbound_email)
2829

29-
@receiver == @mailbox
30+
@receiver == @mailbox
31+
end
32+
else
33+
def matches?(mailbox)
34+
@mailbox = mailbox
35+
@receiver = ApplicationMailbox.router.send(:match_to_mailbox, inbound_email)
36+
37+
@receiver == @mailbox
38+
end
3039
end
3140

3241
def failure_message
@@ -41,7 +50,7 @@ def failure_message_when_negated
4150
"expected #{describe_inbound_email} not to route to #{mailbox}"
4251
end
4352

44-
private
53+
private
4554

4655
attr_reader :inbound_email, :mailbox, :receiver
4756

0 commit comments

Comments
 (0)