-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
286 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,40 +126,249 @@ class EMailboxTest < ActionMailbox::TestCase | |
end | ||
end | ||
|
||
test 'message threads' do | ||
test 'emails are mapped into same threads if the subjects are same, recipients are same and the in-reply-to header is not present' do | ||
Apartment::Tenant.switch @restarone_subdomain do | ||
perform_enqueued_jobs do | ||
assert_difference "MessageThread.all.reload.size" , +1 do | ||
assert_difference "Message.all.reload.size", +2 do | ||
subject_line = "Hello world!" | ||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: subject_line, | ||
body: "Hello?" | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: subject_line, | ||
body: "Hello?" | ||
|
||
assert MessageThread.all.last.subject | ||
assert Message.last.from | ||
|
||
|
||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: subject_line, | ||
body: "Hello?" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
test 'emails are mapped into same threads if the subjects differ by standard prefixes for replies and email forwarding, recipients are same and the in-reply-to header is not present' do | ||
Apartment::Tenant.switch @restarone_subdomain do | ||
perform_enqueued_jobs do | ||
assert_difference "MessageThread.all.reload.size" , +1 do | ||
assert_difference "Message.all.reload.size", +2 do | ||
subject_line = "Hello world!" | ||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: subject_line, | ||
body: "Hello?" | ||
|
||
assert MessageThread.all.last.subject | ||
assert Message.last.from | ||
|
||
|
||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: 'Fw: ' + subject_line, | ||
body: "Hello?" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
test 'emails are mapped into different threads if the subjects differ by standard prefixed for replies and email forwarding but recipients are different and the in-reply-to header is not present' do | ||
Apartment::Tenant.switch @restarone_subdomain do | ||
perform_enqueued_jobs do | ||
assert_difference "MessageThread.all.reload.size" , +2 do | ||
assert_difference "Message.all.reload.size", +2 do | ||
subject_line = "Hello world!" | ||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: subject_line, | ||
body: "Hello?" | ||
|
||
assert MessageThread.all.last.subject | ||
assert Message.last.from | ||
|
||
|
||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"if.else" <[email protected]>', | ||
subject: subject_line, | ||
body: "Hello?" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
test 'emails are mapped into different threads if the subjects are same but recipients are different and the in-reply-to header is not present' do | ||
Apartment::Tenant.switch @restarone_subdomain do | ||
perform_enqueued_jobs do | ||
assert_difference "MessageThread.all.reload.size" , +2 do | ||
assert_difference "Message.all.reload.size", +2 do | ||
subject_line = "Hello world!" | ||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: subject_line, | ||
body: "Hello?" | ||
|
||
assert MessageThread.all.last.subject | ||
assert Message.last.from | ||
|
||
|
||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"if.else" <[email protected]>', | ||
subject: subject_line, | ||
body: "Hello?" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
test 'emails are mapped into same threads when the in-reply-to header refers to one of the email from the same thread' do | ||
Apartment::Tenant.switch @restarone_subdomain do | ||
perform_enqueued_jobs do | ||
assert_difference "MessageThread.all.reload.size" , +1 do | ||
assert_difference "Message.all.reload.size", +2 do | ||
subject_line = "Hello world!" | ||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: subject_line, | ||
body: "Hello?" | ||
assert MessageThread.all.last.subject | ||
assert Message.last.from | ||
|
||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: subject_line, | ||
body: "Hello?", | ||
'in-reply-to': "<#{Message.last.email_message_id}>" | ||
end | ||
end | ||
|
||
assert_no_difference "MessageThread.all.reload.size" do | ||
assert_difference "Message.all.reload.size", +2 do | ||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: 'subject_line', | ||
body: "Hello?" | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: 'subject_line', | ||
body: "Hello?", | ||
'in-reply-to': "<#{Message.last.email_message_id}>" | ||
|
||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: 'subject_line 22', | ||
body: "Hello?", | ||
'in-reply-to': "<#{Message.last.email_message_id}>" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
test 'emails are mapped into same threads when the in-reply-to header refers to one of the email from the same thread even if the subject and recipients are different' do | ||
Apartment::Tenant.switch @restarone_subdomain do | ||
perform_enqueued_jobs do | ||
assert_difference "MessageThread.all.reload.size" , +1 do | ||
assert_difference "Message.all.reload.size", +2 do | ||
subject_line = "Hello world!" | ||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: subject_line, | ||
body: "Hello?" | ||
assert MessageThread.all.last.subject | ||
assert Message.last.from | ||
|
||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"if.else" <[email protected]>', | ||
subject: 'Test: ' + subject_line, | ||
body: "Hello?", | ||
'in-reply-to': "<#{Message.last.email_message_id}>" | ||
end | ||
end | ||
|
||
assert_no_difference "MessageThread.all.reload.size" do | ||
assert_difference "Message.all.reload.size", +2 do | ||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"else" <[email protected]>', | ||
subject: 'subject_line', | ||
body: "Hello?", | ||
'in-reply-to': "<#{Message.last.email_message_id}>" | ||
|
||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"when.else" <[email protected]>', | ||
subject: 'subject_line 22', | ||
body: "Hello?", | ||
'in-reply-to': "<#{Message.last.email_message_id}>" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
# This is how github sends email notifications. | ||
test 'emails are mapped into same threads when the in-reply-to header refers to a different non-existent email message-id but the subject and recipients are same' do | ||
in_reply_to = "<restarone/violet_rails/test_email/[email protected]>" | ||
subject_line = "Hello world!" | ||
|
||
Apartment::Tenant.switch @restarone_subdomain do | ||
perform_enqueued_jobs do | ||
assert_difference "MessageThread.all.reload.size" , +1 do | ||
assert_difference "Message.all.reload.size", +2 do | ||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"Violet Rails" <[email protected]>', | ||
subject: subject_line, | ||
body: "Hello?", | ||
'in-reply-to': in_reply_to, | ||
references: in_reply_to | ||
|
||
assert MessageThread.all.last.subject | ||
assert Message.last.from | ||
|
||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"Violet Rails" <[email protected]>', | ||
subject: 'Re: ' + subject_line, | ||
body: "Hello?", | ||
'in-reply-to': in_reply_to, | ||
references: in_reply_to | ||
end | ||
end | ||
|
||
assert_no_difference "MessageThread.all.reload.size" do | ||
assert_difference "Message.all.reload.size", +2 do | ||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"Violet Rails" <[email protected]>', | ||
subject: 'FWD: ' + subject_line, | ||
body: "Hello?", | ||
'in-reply-to': in_reply_to, | ||
references: in_reply_to | ||
|
||
receive_inbound_email_from_mail \ | ||
to: '"Don Restarone" <[email protected]>', | ||
from: '"Violet Rails" <[email protected]>', | ||
subject: 're: ' + subject_line, | ||
body: "Hello?", | ||
'in-reply-to': in_reply_to, | ||
references: in_reply_to | ||
end | ||
end | ||
end | ||
|