aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--spec/mailers/outgoing_mailer_spec.rb111
1 files changed, 52 insertions, 59 deletions
diff --git a/spec/mailers/outgoing_mailer_spec.rb b/spec/mailers/outgoing_mailer_spec.rb
index 5d1ea2dfb..a11d56dd3 100644
--- a/spec/mailers/outgoing_mailer_spec.rb
+++ b/spec/mailers/outgoing_mailer_spec.rb
@@ -1,73 +1,66 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe OutgoingMailer, " when working out follow up addresses" do
- # This is done with fixtures as the code is a bit tangled with the way it
- # calls TMail. XXX untangle it and make these tests spread out and using
- # mocks. Put parts of the tests in spec/lib/tmail_extensions.rb
- before(:each) do
- load_raw_emails_data
+describe OutgoingMailer, " when working out follow up names and addresses" do
+
+ before do
+ @info_request = mock_model(InfoRequest,
+ :recipient_name_and_email => 'test <test@example.com>',
+ :recipient_email => 'test@example.com')
+ @info_request.stub_chain(:public_body, :name).and_return("Test Authority")
+ @incoming_message = mock_model(IncomingMessage,
+ :from_email => 'specific@example.com',
+ :safe_mail_from => 'Specific Person')
end
- it "should parse them right" do
- ir = info_requests(:fancy_dog_request)
- im = ir.incoming_messages[0]
-
- # check the basic entry in the fixture is fine
- OutgoingMailer.name_and_email_for_followup(ir, im).should == "FOI Person <foiperson@localhost>"
- OutgoingMailer.name_for_followup(ir, im).should == "FOI Person"
- OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
+ def expect_address(info_request, incoming_message, expected_result)
+ mail = create_message_from(from_line)
+ name = MailHandler.get_from_name(mail)
+ email = MailHandler.get_from_address(mail)
+ address = MailHandler.address_from_name_and_email(name, email).to_s
+ [name, email, address].should == expected_result
end
- it "should work when there is only an email address" do
- ir = info_requests(:fancy_dog_request)
- im = ir.incoming_messages[0]
+ describe 'if there is no incoming message being replied to' do
- im.raw_email.data = im.raw_email.data.sub("\"FOI Person\" <foiperson@localhost>", "foiperson@localhost")
- im.parse_raw_email! true
+ it 'should return the name and email address of the public body' do
+ OutgoingMailer.name_and_email_for_followup(@info_request, nil).should == 'test <test@example.com>'
+ OutgoingMailer.name_for_followup(@info_request, nil).should == 'Test Authority'
+ OutgoingMailer.email_for_followup(@info_request, nil).should == 'test@example.com'
+ end
- # check the basic entry in the fixture is fine
- OutgoingMailer.name_and_email_for_followup(ir, im).should == "foiperson@localhost"
- OutgoingMailer.name_for_followup(ir, im).should == "Geraldine Quango"
- OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
end
- it "should quote funny characters" do
- ir = info_requests(:fancy_dog_request)
- im = ir.incoming_messages[0]
+ describe 'if the incoming message being replied to is not valid to reply to' do
- im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI [ Person")
- im.parse_raw_email! true
+ before do
+ @incoming_message.stub!(:valid_to_reply_to?).and_return(false)
+ end
- # check the basic entry in the fixture is fine
- OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI [ Person\" <foiperson@localhost>"
- OutgoingMailer.name_for_followup(ir, im).should == "FOI [ Person"
- OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
+ it 'should return the safe name and email address of the public body' do
+ OutgoingMailer.name_and_email_for_followup(@info_request, @incoming_message).should == 'test <test@example.com>'
+ OutgoingMailer.name_for_followup(@info_request, @incoming_message).should == 'Test Authority'
+ OutgoingMailer.email_for_followup(@info_request, @incoming_message).should == 'test@example.com'
+ end
end
- it "should quote quotes" do
- ir = info_requests(:fancy_dog_request)
- im = ir.incoming_messages[0]
+ describe 'if the incoming message is valid to reply to' do
- im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI \\\" Person")
- im.parse_raw_email! true
+ before do
+ @incoming_message.stub!(:valid_to_reply_to?).and_return(true)
+ end
- # check the basic entry in the fixture is fine
- OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI \\\" Person\" <foiperson@localhost>"
- OutgoingMailer.name_for_followup(ir, im).should == "FOI \" Person"
- OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
- end
+ it 'should return the name and email address from the incoming message' do
+ OutgoingMailer.name_and_email_for_followup(@info_request, @incoming_message).should == 'Specific Person <specific@example.com>'
+ OutgoingMailer.name_for_followup(@info_request, @incoming_message).should == 'Specific Person'
+ OutgoingMailer.email_for_followup(@info_request, @incoming_message).should == 'specific@example.com'
+ end
- it "should quote @ signs" do
- ir = info_requests(:fancy_dog_request)
- im = ir.incoming_messages[0]
+ it 'should return the name of the public body if the incoming message does not have
+ a safe name' do
+ @incoming_message.stub!(:safe_mail_from).and_return(nil)
+ OutgoingMailer.name_for_followup(@info_request, @incoming_message).should == 'Test Authority'
+ end
- im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI @ Person")
- im.parse_raw_email! true
-
- # check the basic entry in the fixture is fine
- OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI @ Person\" <foiperson@localhost>"
- OutgoingMailer.name_for_followup(ir, im).should == "FOI @ Person"
- OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
end
end
@@ -79,21 +72,21 @@ describe OutgoingMailer, "when working out follow up subjects" do
end
it "should prefix the title with 'Freedom of Information request -' for initial requests" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
ir.email_subject_request.should == "Freedom of Information request - Why do you have & such a fancy dog?"
end
it "should use 'Re:' and inital request subject for followups which aren't replies to particular messages" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
om = outgoing_messages(:useless_outgoing_message)
OutgoingMailer.subject_for_followup(ir, om).should == "Re: Freedom of Information request - Why do you have & such a fancy dog?"
end
it "should prefix with Re: the subject of the message being replied to" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
om = outgoing_messages(:useless_outgoing_message)
om.incoming_message_followup = im
@@ -102,7 +95,7 @@ describe OutgoingMailer, "when working out follow up subjects" do
end
it "should not add Re: prefix if there already is such a prefix" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
om = outgoing_messages(:useless_outgoing_message)
om.incoming_message_followup = im
@@ -112,19 +105,19 @@ describe OutgoingMailer, "when working out follow up subjects" do
end
it "should not add Re: prefix if there already is a lower case re: prefix" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
om = outgoing_messages(:useless_outgoing_message)
om.incoming_message_followup = im
im.raw_email.data = im.raw_email.data.sub("Subject: Geraldine FOI Code AZXB421", "Subject: re: Geraldine FOI Code AZXB421")
im.parse_raw_email! true
-
+
OutgoingMailer.subject_for_followup(ir, om).should == "re: Geraldine FOI Code AZXB421"
end
it "should use 'Re:' and initial request subject when replying to failed delivery notifications" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
om = outgoing_messages(:useless_outgoing_message)
om.incoming_message_followup = im