-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '7879-requests-sent-to-multiple-addresses' into develop
- Loading branch information
Showing
5 changed files
with
169 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,85 @@ | |
deliveries.clear | ||
end | ||
|
||
it "should append the email to each exact request address, unless that request has already received the email" do | ||
ir = info_requests(:fancy_dog_request) | ||
raw_email_data = <<~EML | ||
From: EMAIL_FROM | ||
To: EMAIL_TO | ||
Message-ID: [email protected] | ||
Subject: Basic Email | ||
Hello, World | ||
EML | ||
expect(ir.incoming_messages.count).to eq(1) # in the fixture | ||
receive_incoming_mail( | ||
raw_email_data, | ||
email_to: ir.incoming_email | ||
) | ||
expect(ir.incoming_messages.count).to eq(2) # one more arrives | ||
# send the email again | ||
receive_incoming_mail( | ||
raw_email_data, | ||
email_to: ir.incoming_email | ||
) | ||
# this shouldn't add to the number of incoming mails | ||
expect(ir.incoming_messages.count).to eq(2) | ||
# send an email with a new Message-ID | ||
raw_email_data = <<~EML | ||
From: EMAIL_FROM | ||
To: EMAIL_TO | ||
Message-ID: [email protected] | ||
Subject: Basic Email | ||
Hello, World | ||
EML | ||
receive_incoming_mail( | ||
raw_email_data, | ||
email_to: ir.incoming_email | ||
) | ||
# this should add to the number of incoming mails | ||
expect(ir.incoming_messages.count).to eq(3) | ||
end | ||
|
||
it 'should append the email to every request matches, unless the requests has already received the email' do | ||
info_request_1 = FactoryBot.create(:info_request) | ||
info_request_2 = FactoryBot.create(:info_request) | ||
|
||
expect(info_request_1.incoming_messages.count).to eq(0) | ||
expect(info_request_2.incoming_messages.count).to eq(0) | ||
|
||
raw_email_data = <<~EML | ||
From: EMAIL_FROM | ||
To: EMAIL_TO | ||
Message-ID: [email protected] | ||
Subject: Basic Email | ||
Hello, World | ||
EML | ||
|
||
# send email to one request | ||
receive_incoming_mail( | ||
raw_email_data, | ||
email_to: info_request_1.incoming_email | ||
) | ||
|
||
expect(info_request_1.incoming_messages.count).to eq(1) | ||
expect(info_request_2.incoming_messages.count).to eq(0) | ||
|
||
# send same email to both requests, should only be delivered to the | ||
# request which hasn't already received the email | ||
receive_incoming_mail( | ||
raw_email_data, | ||
email_to: [ | ||
info_request_1.incoming_email, | ||
info_request_2.incoming_email | ||
].join(', ') | ||
) | ||
|
||
expect(info_request_1.incoming_messages.count).to eq(1) | ||
expect(info_request_2.incoming_messages.count).to eq(1) | ||
end | ||
|
||
it "should store mail in holding pen and send to admin when the email is not to any information request" do | ||
ir = info_requests(:fancy_dog_request) | ||
expect(ir.incoming_messages.count).to eq(1) | ||
|
@@ -92,17 +171,6 @@ | |
deliveries.clear | ||
end | ||
|
||
it "puts messages with multiple request addresses in Bcc: in the holding pen" do | ||
request1 = FactoryBot.create(:info_request) | ||
request2 = FactoryBot.create(:info_request) | ||
request3 = FactoryBot.create(:info_request) | ||
bcc_addrs = [request1, request2, request3].map(&:incoming_email) | ||
receive_incoming_mail('bcc-contact-reply.email', | ||
email_to: 'dummy@localhost', | ||
email_bcc: bcc_addrs.join(', ')) | ||
expect(InfoRequest.holding_pen_request.incoming_messages.count).to eq(1) | ||
end | ||
|
||
it "should parse attachments from mails sent with apple mail" do | ||
ir = info_requests(:fancy_dog_request) | ||
expect(ir.incoming_messages.count).to eq(1) | ||
|
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 |
---|---|---|
|
@@ -1054,6 +1054,23 @@ | |
ActionMailer::Base.deliveries.clear | ||
end | ||
|
||
context 'when email has already been received' do | ||
|
||
let(:info_request) { FactoryBot.create(:info_request) } | ||
|
||
before do | ||
allow(info_request).to receive(:already_received?).and_return(true) | ||
end | ||
|
||
it 'does not create a new incoming message' do | ||
email, raw_email = email_and_raw_email | ||
expect { info_request.receive(email, raw_email) }.to_not change { | ||
info_request.incoming_messages.count | ||
} | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
describe "#url_title" do | ||
|
@@ -1567,6 +1584,53 @@ | |
|
||
end | ||
|
||
describe '#already_received?' do | ||
it 'returns false if email has no Message-ID header' do | ||
info_request = FactoryBot.build(:info_request) | ||
|
||
email = Mail.new( | ||
<<~EML | ||
Subject: Basic Email | ||
Hello, World | ||
EML | ||
) | ||
|
||
expect(info_request.already_received?(email)).to eq(false) | ||
end | ||
|
||
it 'returns false if a message with the same Message-ID has not been received' do | ||
info_request = FactoryBot.build(:info_request) | ||
|
||
email = Mail.new( | ||
<<~EML | ||
Message-ID: [email protected] | ||
Subject: Basic Email | ||
Hello, World | ||
EML | ||
) | ||
|
||
expect(info_request.already_received?(email)).to eq(false) | ||
end | ||
|
||
it 'returns true if a message with the same Message-ID has already been received' do | ||
info_request = FactoryBot.create(:info_request) | ||
|
||
raw_email_data = <<~EML | ||
Message-ID: [email protected] | ||
Subject: Basic Email | ||
Hello, World | ||
EML | ||
email, raw_email = email_and_raw_email(raw_email: raw_email_data) | ||
|
||
info_request.receive(email, raw_email) | ||
expect(info_request.incoming_messages.count).to eq(1) | ||
expect(info_request.already_received?(email)).to eq(true) | ||
end | ||
end | ||
|
||
describe '#is_external?' do | ||
|
||
it 'returns true if there is an external url' do | ||
|
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