From 9dd0b8b27bc7072c7e6afe54ff3693f653b7c90c Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 8 Nov 2012 16:18:25 +0000 Subject: Make error message expectation slightly less specific - message format is slightly different under ruby 1.9. --- spec/models/application_mailer_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spec/models') diff --git a/spec/models/application_mailer_spec.rb b/spec/models/application_mailer_spec.rb index a90f79c01..acf5f43bc 100644 --- a/spec/models/application_mailer_spec.rb +++ b/spec/models/application_mailer_spec.rb @@ -80,7 +80,8 @@ describe ApplicationMailer do it 'should raise an error if the template is in neither core nor theme' do prepend_theme_views('theme_one') - lambda{ ApplicationMailer.create_neither() }.should raise_error('Missing template application_mailer/neither.erb in view path spec/fixtures/theme_views/theme_one:spec/fixtures/theme_views/core') + expected_error = 'Missing template application_mailer/neither.erb in view path' + lambda{ ApplicationMailer.create_neither() }.should raise_error(/#{expected_error}/) end it 'should render a multipart email using a theme template' do @@ -125,7 +126,8 @@ describe ApplicationMailer do it 'should raise an error if the template is in neither core nor theme' do append_theme_views('theme_one') - lambda{ ApplicationMailer.create_neither() }.should raise_error('Missing template application_mailer/neither.erb in view path spec/fixtures/theme_views/core:spec/fixtures/theme_views/theme_one') + expected_error = 'Missing template application_mailer/neither.erb in view path' + lambda{ ApplicationMailer.create_neither() }.should raise_error(/#{expected_error}/) end it 'should render a multipart email using a core template' do -- cgit v1.2.3 From 7412af2865c984dab0b5897d5e2050e0a45f25d3 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 12:06:16 +0000 Subject: Use mailhandler method in incoming message specs. --- spec/models/incoming_message_spec.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'spec/models') diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index b038c43d9..9e6b0fe33 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -405,8 +405,7 @@ describe IncomingMessage, " when uudecoding bad messages" do it "should be able to do it at all" do mail_body = load_file_fixture('incoming-request-bad-uuencoding.email') - mail = TMail::Mail.parse(mail_body) - mail.base64_decode + mail = MailHandler.mail_from_raw_email(mail_body) im = incoming_messages(:useless_incoming_message) im.stub!(:mail).and_return(mail) im.extract_attachments! @@ -419,8 +418,7 @@ describe IncomingMessage, " when uudecoding bad messages" do it "should apply censor rules" do mail_body = load_file_fixture('incoming-request-bad-uuencoding.email') - mail = TMail::Mail.parse(mail_body) - mail.base64_decode + mail = MailHandler.mail_from_raw_email(mail_body) im = incoming_messages(:useless_incoming_message) im.stub!(:mail).and_return(mail) @@ -449,8 +447,7 @@ describe IncomingMessage, "when messages are attached to messages" do it "should flatten all the attachments out" do mail_body = load_file_fixture('incoming-request-attach-attachments.email') - mail = TMail::Mail.parse(mail_body) - mail.base64_decode + mail = MailHandler.mail_from_raw_email(mail_body) im = incoming_messages(:useless_incoming_message) im.stub!(:mail).and_return(mail) @@ -474,8 +471,7 @@ describe IncomingMessage, "when Outlook messages are attached to messages" do it "should flatten all the attachments out" do mail_body = load_file_fixture('incoming-request-oft-attachments.email') - mail = TMail::Mail.parse(mail_body) - mail.base64_decode + mail = MailHandler.mail_from_raw_email(mail_body) im = incoming_messages(:useless_incoming_message) im.stub!(:mail).and_return(mail) @@ -496,8 +492,7 @@ describe IncomingMessage, "when TNEF attachments are attached to messages" do it "should flatten all the attachments out" do mail_body = load_file_fixture('incoming-request-tnef-attachments.email') - mail = TMail::Mail.parse(mail_body) - mail.base64_decode + mail = MailHandler.mail_from_raw_email(mail_body) im = incoming_messages(:useless_incoming_message) im.stub!(:mail).and_return(mail) -- cgit v1.2.3 From 23e99ffb72361161ef8cff4d0d79efca83326c80 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 12:09:25 +0000 Subject: Factor out method for getting a mail object from a fixture file. --- spec/models/incoming_message_spec.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'spec/models') diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index 9e6b0fe33..a94117c60 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -403,9 +403,10 @@ describe IncomingMessage, " when uudecoding bad messages" do load_raw_emails_data end + + it "should be able to do it at all" do - mail_body = load_file_fixture('incoming-request-bad-uuencoding.email') - mail = MailHandler.mail_from_raw_email(mail_body) + mail = get_fixture_mail('incoming-request-bad-uuencoding.email') im = incoming_messages(:useless_incoming_message) im.stub!(:mail).and_return(mail) im.extract_attachments! @@ -417,8 +418,7 @@ describe IncomingMessage, " when uudecoding bad messages" do end it "should apply censor rules" do - mail_body = load_file_fixture('incoming-request-bad-uuencoding.email') - mail = MailHandler.mail_from_raw_email(mail_body) + mail = get_fixture_mail('incoming-request-bad-uuencoding.email') im = incoming_messages(:useless_incoming_message) im.stub!(:mail).and_return(mail) @@ -446,8 +446,7 @@ describe IncomingMessage, "when messages are attached to messages" do end it "should flatten all the attachments out" do - mail_body = load_file_fixture('incoming-request-attach-attachments.email') - mail = MailHandler.mail_from_raw_email(mail_body) + mail = get_fixture_mail('incoming-request-attach-attachments.email') im = incoming_messages(:useless_incoming_message) im.stub!(:mail).and_return(mail) @@ -470,8 +469,7 @@ describe IncomingMessage, "when Outlook messages are attached to messages" do end it "should flatten all the attachments out" do - mail_body = load_file_fixture('incoming-request-oft-attachments.email') - mail = MailHandler.mail_from_raw_email(mail_body) + mail = get_fixture_mail('incoming-request-oft-attachments.email') im = incoming_messages(:useless_incoming_message) im.stub!(:mail).and_return(mail) @@ -491,8 +489,7 @@ describe IncomingMessage, "when TNEF attachments are attached to messages" do end it "should flatten all the attachments out" do - mail_body = load_file_fixture('incoming-request-tnef-attachments.email') - mail = MailHandler.mail_from_raw_email(mail_body) + mail = get_fixture_mail('incoming-request-tnef-attachments.email') im = incoming_messages(:useless_incoming_message) im.stub!(:mail).and_return(mail) -- cgit v1.2.3 From 23e87c046e23ad1af1d8b70d3ea25c5d37a74a96 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 12:12:09 +0000 Subject: Don't load raw emails data in specs that don't use it. --- spec/models/incoming_message_spec.rb | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'spec/models') diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index a94117c60..2ae98564c 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -399,12 +399,6 @@ end describe IncomingMessage, " when uudecoding bad messages" do - before(:each) do - load_raw_emails_data - end - - - it "should be able to do it at all" do mail = get_fixture_mail('incoming-request-bad-uuencoding.email') im = incoming_messages(:useless_incoming_message) @@ -441,10 +435,6 @@ end describe IncomingMessage, "when messages are attached to messages" do - before(:each) do - load_raw_emails_data - end - it "should flatten all the attachments out" do mail = get_fixture_mail('incoming-request-attach-attachments.email') @@ -464,10 +454,6 @@ end describe IncomingMessage, "when Outlook messages are attached to messages" do - before(:each) do - load_raw_emails_data - end - it "should flatten all the attachments out" do mail = get_fixture_mail('incoming-request-oft-attachments.email') @@ -484,10 +470,6 @@ end describe IncomingMessage, "when TNEF attachments are attached to messages" do - before(:each) do - load_raw_emails_data - end - it "should flatten all the attachments out" do mail = get_fixture_mail('incoming-request-tnef-attachments.email') -- cgit v1.2.3 From 4bdab94e9d4f0a64647e5f8534c1fea8b4ba2809 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 14:04:55 +0000 Subject: Move TMail extensions to mail handler. --- spec/models/incoming_message_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'spec/models') diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index 2ae98564c..fdbcd1e23 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -85,6 +85,26 @@ describe IncomingMessage, " when dealing with incoming mail" do end end + + it "should load an email with funny MIME settings" do + ActionMailer::Base.deliveries.clear + # just send it to the holding pen + InfoRequest.holding_pen_request.incoming_messages.size.should == 0 + receive_incoming_mail("humberside-police-odd-mime-type.email", 'dummy') + InfoRequest.holding_pen_request.incoming_messages.size.should == 1 + + # clear the notification of new message in holding pen + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + deliveries.clear + + incoming_message = InfoRequest.holding_pen_request.incoming_messages[0] + + # This will raise an error if the bug in TMail hasn't been fixed + incoming_message.get_body_for_html_display() + end + + end describe IncomingMessage, "when parsing HTML mail" do -- cgit v1.2.3 From c22653c85c8029bf2ee193eb892bad1f3d0e93fe Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 14:15:56 +0000 Subject: Use mail handler in request mailer spec. --- spec/models/request_mailer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb index 906756784..0f09e6926 100644 --- a/spec/models/request_mailer_spec.rb +++ b/spec/models/request_mailer_spec.rb @@ -98,7 +98,7 @@ describe RequestMailer, " when receiving incoming mail" do mail.multipart?.should == true mail.parts.size.should == 2 message_part = mail.parts[0].to_s - bounced_mail = TMail::Mail.parse(mail.parts[1].body) + bounced_mail = MailHandler.mail_from_raw_email(mail.parts[1].body, decode=false) bounced_mail.to.should == [ ir.incoming_email ] bounced_mail.from.should == [ 'geraldinequango@localhost' ] bounced_mail.body.include?("That's so totally a rubbish question").should be_true -- cgit v1.2.3 From f5ced2133cd1a66e18b225208fa96f4f36a20889 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 16:56:06 +0000 Subject: Move address_from_name_and_email to mail handler. --- spec/models/track_mailer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/track_mailer_spec.rb b/spec/models/track_mailer_spec.rb index 1bf77dab5..9bf03c3d0 100644 --- a/spec/models/track_mailer_spec.rb +++ b/spec/models/track_mailer_spec.rb @@ -169,7 +169,7 @@ describe TrackMailer do it 'should deliver one email, with right headers' do @user = mock_model(User, - :name_and_email => TMail::Address.address_from_name_and_email('Tippy Test', 'tippy@localhost'), + :name_and_email => MailHandler.address_from_name_and_email('Tippy Test', 'tippy@localhost'), :url_name => 'tippy_test' ) -- cgit v1.2.3 From 125ca970ad4e2b5e424265c632ae31c6dde62da7 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 17:25:11 +0000 Subject: Wrap address parsing in a address_from_string method in the mail handler. --- spec/models/info_request_event_spec.rb | 47 +++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'spec/models') diff --git a/spec/models/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb index 7352f3be0..796f8b840 100644 --- a/spec/models/info_request_event_spec.rb +++ b/spec/models/info_request_event_spec.rb @@ -54,36 +54,71 @@ describe InfoRequestEvent do end - describe "doing search/index stuff" do + describe "doing search/index stuff" do before(:each) do load_raw_emails_data parse_all_incoming_messages end - it 'should get search text for outgoing messages' do + it 'should get search text for outgoing messages' do event = info_request_events(:useless_outgoing_message_event) message = outgoing_messages(:useless_outgoing_message).body event.search_text_main.should == message + "\n\n" end - it 'should get search text for incoming messages' do + it 'should get search text for incoming messages' do event = info_request_events(:useless_incoming_message_event) event.search_text_main.strip.should == "No way! I'm not going to tell you that in a month of Thursdays.\n\nThe Geraldine Quango" end - it 'should get clipped text for incoming messages, and cache it too' do + it 'should get clipped text for incoming messages, and cache it too' do event = info_request_events(:useless_incoming_message_event) - + event.incoming_message_selective_columns("cached_main_body_text_folded").cached_main_body_text_folded = nil event.search_text_main(true).strip.should == "No way! I'm not going to tell you that in a month of Thursdays.\n\nThe Geraldine Quango" event.incoming_message_selective_columns("cached_main_body_text_folded").cached_main_body_text_folded.should_not == nil end - end + describe 'when asked if it has the same email as a previous send' do + + before do + @info_request_event = InfoRequestEvent.new + end + + it 'should return true if the email in its params and the previous email the request was sent to are both nil' do + @info_request_event.stub!(:params).and_return({}) + @info_request_event.stub_chain(:info_request, :get_previous_email_sent_to).and_return(nil) + @info_request_event.same_email_as_previous_send?.should be_true + end + + it 'should return false if one email address exists and the other does not' do + @info_request_event.stub!(:params).and_return(:email => 'test@example.com') + @info_request_event.stub_chain(:info_request, :get_previous_email_sent_to).and_return(nil) + @info_request_event.same_email_as_previous_send?.should be_false + end + it 'should return true if the addresses are identical' do + @info_request_event.stub!(:params).and_return(:email => 'test@example.com') + @info_request_event.stub_chain(:info_request, :get_previous_email_sent_to).and_return('test@example.com') + @info_request_event.same_email_as_previous_send?.should be_true + end + + it 'should return false if the addresses are different' do + @info_request_event.stub!(:params).and_return(:email => 'test@example.com') + @info_request_event.stub_chain(:info_request, :get_previous_email_sent_to).and_return('different@example.com') + @info_request_event.same_email_as_previous_send?.should be_false + end + + it 'should return true if the addresses have different formats' do + @info_request_event.stub!(:params).and_return(:email => 'A Test ') + @info_request_event.stub_chain(:info_request, :get_previous_email_sent_to).and_return('test@example.com') + @info_request_event.same_email_as_previous_send?.should be_true + end + + end end -- cgit v1.2.3 From 640aa149fd321658a33466df7b53947b78bccd81 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Wed, 21 Nov 2012 18:51:05 +0000 Subject: Use new function that copies existing xapian index in spec setup where a clean copy of the xapian index with fixtures loaded is required. --- spec/models/xapian_spec.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'spec/models') diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index 195b39eee..8c99d550f 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -4,9 +4,9 @@ describe User, " when indexing users with Xapian" do before(:each) do load_raw_emails_data - rebuild_xapian_index + get_fixtures_xapian_index end - + it "should search by name" do # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) xapian_object = InfoRequest.full_search([User], "Silly", 'created_at', true, nil, 100, 1) @@ -21,7 +21,7 @@ describe User, " when indexing users with Xapian" do xapian_object = InfoRequest.full_search([User], "stuff", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 1 xapian_object.results[0][:model].should == user - + user.about_me = "I am really an aardvark, true story." user.save! update_xapian_index @@ -38,7 +38,7 @@ end describe PublicBody, " when indexing public bodies with Xapian" do before(:each) do load_raw_emails_data - rebuild_xapian_index + get_fixtures_xapian_index end it "should search index the main name field" do @@ -71,7 +71,7 @@ describe PublicBody, " when indexing requests by body they are to" do before(:each) do load_raw_emails_data - rebuild_xapian_index + get_fixtures_xapian_index end it "should find requests to the body" do @@ -126,7 +126,7 @@ end describe User, " when indexing requests by user they are from" do before(:each) do load_raw_emails_data - rebuild_xapian_index + get_fixtures_xapian_index end it "should find requests from the user" do @@ -204,7 +204,7 @@ end describe User, " when indexing comments by user they are by" do before(:each) do load_raw_emails_data - rebuild_xapian_index + get_fixtures_xapian_index end it "should find requests from the user" do @@ -239,7 +239,7 @@ end describe InfoRequest, " when indexing requests by their title" do before(:each) do load_raw_emails_data - rebuild_xapian_index + get_fixtures_xapian_index end it "should find events for the request" do @@ -268,7 +268,7 @@ end describe InfoRequest, " when indexing requests by tag" do before(:each) do load_raw_emails_data - rebuild_xapian_index + get_fixtures_xapian_index end it "should find request by tag, even when changes" do @@ -289,7 +289,7 @@ end describe PublicBody, " when indexing authorities by tag" do before(:each) do load_raw_emails_data - rebuild_xapian_index + get_fixtures_xapian_index end it "should find request by tag, even when changes" do @@ -313,7 +313,7 @@ end describe PublicBody, " when only indexing selected things on a rebuild" do before(:each) do load_raw_emails_data - rebuild_xapian_index + get_fixtures_xapian_index end it "should only index what we ask it to" do -- cgit v1.2.3 From 80b12ef56782a11a18b633647cead4847c55c9ab Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 29 Nov 2012 12:25:17 +0000 Subject: Standardize slug generation for external users so that it uses the same underlying method as other slug generation. Fixes #567. --- spec/models/info_request_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'spec/models') diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 2aeac2fec..544852f91 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -2,6 +2,22 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe InfoRequest do + describe 'when generating a user name slug' do + + before do + @public_body = mock_model(PublicBody, :url_name => 'example_body', + :eir_only? => false) + @info_request = InfoRequest.new(:external_url => 'http://www.example.com', + :external_user_name => 'Example User', + :public_body => @public_body) + end + + it 'should generate a slug for an example user name' do + @info_request.user_name_slug.should == 'example_body_example_user' + end + + end + describe "guessing a request from an email" do before(:each) do -- cgit v1.2.3 From 41e3c41d08e97e232bb7cf2e1faec00c9aa0f92b Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 4 Dec 2012 10:50:25 +0000 Subject: Rewrite spec to reflect delegation of low-level mail methods to mail handler, use mail handler methods. --- spec/models/incoming_message_spec.rb | 37 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'spec/models') diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index fdbcd1e23..7afbacc9e 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -194,59 +194,50 @@ describe IncomingMessage, " folding quoted parts of emails" do end describe IncomingMessage, " checking validity to reply to" do - def test_email(result, email, return_path, autosubmitted = nil) - @address = mock(TMail::Address) - @address.stub!(:spec).and_return(email) - - @return_path = mock(TMail::ReturnPathHeader) - @return_path.stub!(:addr).and_return(return_path) - if !autosubmitted.nil? - @autosubmitted = TMail::UnstructuredHeader.new("auto-submitted", autosubmitted) - end - @mail = mock(TMail::Mail) - @mail.stub!(:from_addrs).and_return( [ @address ] ) - @mail.stub!(:[]).with("return-path").and_return(@return_path) - @mail.stub!(:[]).with("auto-submitted").and_return(@autosubmitted) - + def test_email(result, email, empty_return_path, autosubmitted = nil) + @mail = mock('mail') + MailHandler.stub!(:get_from_address).and_return(email) + MailHandler.stub!(:empty_return_path?).with(@mail).and_return(empty_return_path) + MailHandler.stub!(:get_auto_submitted).with(@mail).and_return(autosubmitted) @incoming_message = IncomingMessage.new() @incoming_message.stub!(:mail).and_return(@mail) @incoming_message._calculate_valid_to_reply_to.should == result end it "says a valid email is fine" do - test_email(true, "team@mysociety.org", nil) + test_email(true, "team@mysociety.org", false) end it "says postmaster email is bad" do - test_email(false, "postmaster@mysociety.org", nil) + test_email(false, "postmaster@mysociety.org", false) end it "says Mailer-Daemon email is bad" do - test_email(false, "Mailer-Daemon@mysociety.org", nil) + test_email(false, "Mailer-Daemon@mysociety.org", false) end it "says case mangled MaIler-DaemOn email is bad" do - test_email(false, "MaIler-DaemOn@mysociety.org", nil) + test_email(false, "MaIler-DaemOn@mysociety.org", false) end it "says Auto_Reply email is bad" do - test_email(false, "Auto_Reply@mysociety.org", nil) + test_email(false, "Auto_Reply@mysociety.org", false) end it "says DoNotReply email is bad" do - test_email(false, "DoNotReply@tube.tfl.gov.uk", nil) + test_email(false, "DoNotReply@tube.tfl.gov.uk", false) end it "says a filled-out return-path is fine" do - test_email(true, "team@mysociety.org", "Return-path: ") + test_email(true, "team@mysociety.org", false) end it "says an empty return-path is bad" do - test_email(false, "team@mysociety.org", "<>") + test_email(false, "team@mysociety.org", true) end it "says an auto-submitted keyword is bad" do - test_email(false, "team@mysociety.org", nil, "auto-replied") + test_email(false, "team@mysociety.org", false, "auto-replied") end end -- cgit v1.2.3 From 49c8a6131acbdfe151fe1ab0a0e08616865a4e08 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 4 Dec 2012 12:00:11 +0000 Subject: Rewrite and move spec so that it tests the mail handler method. --- spec/models/incoming_message_spec.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'spec/models') diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index 7afbacc9e..5478f6fc4 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -26,11 +26,6 @@ describe IncomingMessage, " when dealing with incoming mail" do @im.sent_at.should == @im.mail.date end - it "should be able to parse emails with quoted commas in" do - em = "\"Clare College, Cambridge\" " - TMail::Address.parse(em) - end - it "should correctly fold various types of footer" do Dir.glob(File.join(Spec::Runner.configuration.fixture_path, "files", "email-folding-example-*.txt")).each do |file| message = File.read(file) -- cgit v1.2.3 From 2ad6b55a528ac0f747b6804157ed08acb616a437 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 13 Nov 2012 10:58:52 +0000 Subject: Add spec for the adding of headers to plain text bodies in attachments. --- spec/models/incoming_message_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'spec/models') diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index 5478f6fc4..5a3f1a954 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -456,6 +456,19 @@ describe IncomingMessage, "when messages are attached to messages" do 'hello.txt', ] end + + it 'should add headers to attached plain text message bodies' do + mail_body = load_file_fixture('incoming-request-attachment-headers.email') + mail = MailHandler.mail_from_raw_email(mail_body) + + im = incoming_messages(:useless_incoming_message) + im.stub!(:mail).and_return(mail) + + attachments = im.get_attachments_for_display + attachments.size.should == 2 + attachments[0].body.should match('Date: Fri, 23 May 2008') + end + end describe IncomingMessage, "when Outlook messages are attached to messages" do -- cgit v1.2.3 From 56c9a24adfe01d9b962a01a40aefa92e06193f30 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 13 Nov 2012 16:35:18 +0000 Subject: Add spec for handling an RFC822 attachment. Conflicts: spec/models/incoming_message_spec.rb --- spec/models/incoming_message_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'spec/models') diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index 5a3f1a954..1278535f8 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -441,6 +441,24 @@ end describe IncomingMessage, "when messages are attached to messages" do + it 'should expand an RFC822 attachment' do + mail_body = load_file_fixture('rfc822-attachment.email') + mail = MailHandler.mail_from_raw_email(mail_body) + + im = incoming_messages(:useless_incoming_message) + im.stub!(:mail).and_return(mail) + + attachments = im.get_attachments_for_display + attachments.size.should == 1 + attachment = attachments.first + + attachment.content_type.should == 'text/plain' + attachment.filename.should == "Freedom of Information request.txt" + attachment.charset.should == "utf-8" + attachment.within_rfc822_subject.should == "Freedom of Information request" + attachment.hexdigest.should == 'f10fe56e4f2287685a58b71329f09639' + end + it "should flatten all the attachments out" do mail = get_fixture_mail('incoming-request-attach-attachments.email') -- cgit v1.2.3 From 14bbd1d75840add4fd5f8c440b58ac465c306fb6 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 6 Dec 2012 10:23:37 +0000 Subject: Move methods for getting the text out of attachments to the mail handler module. --- spec/models/incoming_message_spec.rb | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'spec/models') diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index 1278535f8..3cfb3d5dd 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -102,27 +102,6 @@ describe IncomingMessage, " when dealing with incoming mail" do end -describe IncomingMessage, "when parsing HTML mail" do - it "should display UTF-8 characters in the plain text version correctly" do - html = "foo është" - plain_text = IncomingMessage._get_attachment_text_internal_one_file('text/html', html) - plain_text.should match(/është/) - end - -end - -describe IncomingMessage, "when getting the attachment text" do - - it "should not raise an error if the expansion of a zip file raises an error" do - mock_entry = mock('ZipFile entry', :file? => true) - mock_entry.stub!(:get_input_stream).and_raise("invalid distance too far back") - Zip::ZipFile.stub!(:open).and_return([mock_entry]) - IncomingMessage._get_attachment_text_internal_one_file('application/zip', "some string") - end - -end - - describe IncomingMessage, " display attachments" do it "should not show slashes in filenames" do @@ -138,7 +117,7 @@ describe IncomingMessage, " display attachments" do # http://www.whatdotheyknow.com/request/post_commercial_manager_librarie#incoming-17233 foi_attachment.within_rfc822_subject = "FOI/09/066 RESPONSE TO FOI REQUEST RECEIVED 21st JANUARY 2009" foi_attachment.content_type = 'text/plain' - foi_attachment.ensure_filename! + foi_attachment.ensure_filename! expected_display_filename = foi_attachment.within_rfc822_subject.gsub(/\//, " ") + ".txt" foi_attachment.display_filename.should == expected_display_filename end @@ -326,12 +305,12 @@ describe IncomingMessage, " when censoring data" do orig_pdf = load_file_fixture('tfl.pdf') pdf = orig_pdf.dup - orig_text = IncomingMessage._get_attachment_text_internal_one_file('application/pdf', pdf) + orig_text = MailHandler._get_attachment_text_internal_one_file('application/pdf', pdf) orig_text.should match(/foi@tfl.gov.uk/) @im.binary_mask_stuff!(pdf, "application/pdf") - masked_text = IncomingMessage._get_attachment_text_internal_one_file('application/pdf', pdf) + masked_text = MailHandler._get_attachment_text_internal_one_file('application/pdf', pdf) masked_text.should_not match(/foi@tfl.gov.uk/) masked_text.should match(/xxx@xxx.xxx.xx/) config['USE_GHOSTSCRIPT_COMPRESSION'] = previous -- cgit v1.2.3 From 1d4ef88e60bcecc5c413cf3b6e6cb76f4bb6eaa1 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 6 Dec 2012 10:43:07 +0000 Subject: Rename _get_attachment_text_internal_one_file to get_attachment_text_one_file as it is now an externally-accessed method of the mail handler module. --- spec/models/incoming_message_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/models') diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index 3cfb3d5dd..46dc3a32c 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -305,12 +305,12 @@ describe IncomingMessage, " when censoring data" do orig_pdf = load_file_fixture('tfl.pdf') pdf = orig_pdf.dup - orig_text = MailHandler._get_attachment_text_internal_one_file('application/pdf', pdf) + orig_text = MailHandler.get_attachment_text_one_file('application/pdf', pdf) orig_text.should match(/foi@tfl.gov.uk/) @im.binary_mask_stuff!(pdf, "application/pdf") - masked_text = MailHandler._get_attachment_text_internal_one_file('application/pdf', pdf) + masked_text = MailHandler.get_attachment_text_one_file('application/pdf', pdf) masked_text.should_not match(/foi@tfl.gov.uk/) masked_text.should match(/xxx@xxx.xxx.xx/) config['USE_GHOSTSCRIPT_COMPRESSION'] = previous -- cgit v1.2.3 From ac1c1329eeebefec8c9952cbae372fe8c4255307 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 6 Dec 2012 16:34:52 +0000 Subject: Convert url in comment to spec. Conflicts: lib/mail_handler/backends/tmail_backend.rb --- spec/models/incoming_message_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec/models') diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index 46dc3a32c..70b323e9f 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -68,6 +68,14 @@ describe IncomingMessage, " when dealing with incoming mail" do message.get_main_body_text_internal.should include("The above text was badly encoded") end + it 'should convert DOS-style linebreaks to Unix style' do + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('dos-linebreaks.email', ir.incoming_email) + message = ir.incoming_messages[1] + message.parse_raw_email! + message.get_main_body_text_internal.should_not match(/\r\n/) + end + it "should fold multiline sections" do { "foo\n--------\nconfidential" => "foo\nFOLDED_QUOTED_SECTION\n", # basic test -- cgit v1.2.3 From e898190fe61a4369ee83e94a24327ff437435b07 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 11 Dec 2012 14:07:54 +0000 Subject: Wrap specs on the extraction of RFC-822 headers in code that sets the ENV timezone. TMail renders headers using localtime, which is not ideal, but we're migrating away from it anyway, so I'm not sure it's worth delving into the internals of TMail to fix it. --- spec/models/incoming_message_spec.rb | 56 ++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) (limited to 'spec/models') diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index 70b323e9f..6fc0ff3cc 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -429,21 +429,25 @@ end describe IncomingMessage, "when messages are attached to messages" do it 'should expand an RFC822 attachment' do - mail_body = load_file_fixture('rfc822-attachment.email') - mail = MailHandler.mail_from_raw_email(mail_body) - - im = incoming_messages(:useless_incoming_message) - im.stub!(:mail).and_return(mail) - - attachments = im.get_attachments_for_display - attachments.size.should == 1 - attachment = attachments.first - - attachment.content_type.should == 'text/plain' - attachment.filename.should == "Freedom of Information request.txt" - attachment.charset.should == "utf-8" - attachment.within_rfc822_subject.should == "Freedom of Information request" - attachment.hexdigest.should == 'f10fe56e4f2287685a58b71329f09639' + # Note that this spec will only pass using Tmail in the timezone set as datetime headers + # are rendered out in the local time - using the Mail gem this is not necessary + with_env_tz('London') do + mail_body = load_file_fixture('rfc822-attachment.email') + mail = MailHandler.mail_from_raw_email(mail_body) + + im = incoming_messages(:useless_incoming_message) + im.stub!(:mail).and_return(mail) + + attachments = im.get_attachments_for_display + attachments.size.should == 1 + attachment = attachments.first + + attachment.content_type.should == 'text/plain' + attachment.filename.should == "Freedom of Information request.txt" + attachment.charset.should == "utf-8" + attachment.within_rfc822_subject.should == "Freedom of Information request" + attachment.hexdigest.should == 'f10fe56e4f2287685a58b71329f09639' + end end it "should flatten all the attachments out" do @@ -463,15 +467,19 @@ describe IncomingMessage, "when messages are attached to messages" do end it 'should add headers to attached plain text message bodies' do - mail_body = load_file_fixture('incoming-request-attachment-headers.email') - mail = MailHandler.mail_from_raw_email(mail_body) - - im = incoming_messages(:useless_incoming_message) - im.stub!(:mail).and_return(mail) - - attachments = im.get_attachments_for_display - attachments.size.should == 2 - attachments[0].body.should match('Date: Fri, 23 May 2008') + # Note that this spec will only pass using Tmail in the timezone set as datetime headers + # are rendered out in the local time - using the Mail gem this is not necessary + with_env_tz('London') do + mail_body = load_file_fixture('incoming-request-attachment-headers.email') + mail = MailHandler.mail_from_raw_email(mail_body) + + im = incoming_messages(:useless_incoming_message) + im.stub!(:mail).and_return(mail) + + attachments = im.get_attachments_for_display + attachments.size.should == 2 + attachments[0].body.should match('Date: Fri, 23 May 2008') + end end end -- cgit v1.2.3