From 6ea3501d7b0bff1194955d0de716bd3f1aba3ca6 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 4 Dec 2012 11:23:38 +0000 Subject: Add specs for getting name, email and formatted address - make them pass with the mail backend. --- spec/lib/mail_handler/mail_handler_spec.rb | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index 8f642d529..6043bf5bc 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -140,3 +140,53 @@ describe 'when asked if there is an empty return path' do MailHandler.empty_return_path?(mail).should == false end end + +describe 'when deriving a name, email and formatted address from a message from a line' do + + def should_render_from_address(from_line, 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 correctly reproduce a simple name and email that does not need quotes' do + should_render_from_address('"FOI Person" ', + ['FOI Person', + 'foiperson@localhost', + 'FOI Person ']) + end + + it 'should render an address with no name' do + should_render_from_address("foiperson@localhost", + [nil, + "foiperson@localhost", + "foiperson@localhost"]) + end + + it 'should quote a name with a square bracked in it' do + should_render_from_address('"FOI [ Person" ', + ['FOI [ Person', + 'foiperson@localhost', + '"FOI [ Person" ']) + end + + it 'should quote a name with an @ in it' do + should_render_from_address('"FOI @ Person" ', + ['FOI @ Person', + 'foiperson@localhost', + '"FOI @ Person" ']) + end + + + it 'should quote a name with quotes in it' do + should_render_from_address('"FOI \" Person" ', + ['FOI " Person', + 'foiperson@localhost', + '"FOI \" Person" ']) + end + + + +end -- cgit v1.2.3