diff options
| -rw-r--r-- | spec/lib/mail_handler/mail_handler_spec.rb | 24 | ||||
| -rw-r--r-- | spec/lib/timezone_fixes_spec.rb | 16 | ||||
| -rw-r--r-- | spec/models/incoming_message_spec.rb | 56 | ||||
| -rw-r--r-- | spec/spec_helper.rb | 15 | 
4 files changed, 61 insertions, 50 deletions
| diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index ae65210f2..48c32e2bc 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -283,16 +283,20 @@ describe 'when getting attachment attributes' do      end      it 'should expand a mail attached as text' do -        mail = get_fixture_mail('rfc822-attachment.email') -        attributes = MailHandler.get_attachment_attributes(mail) -        attributes.size.should == 2 -        rfc_attachment = attributes[1] -        rfc_attachment[:within_rfc822_subject].should == 'Freedom of Information request' -        headers = ['Date: Thu, 13 Mar 2008 16:57:33 +0000', -                   'Subject: Freedom of Information request', -                   'From: An FOI Officer <foi.officer@example.com>', -                   'To: request-bounce-xx-xxxxx@whatdotheyno.com'] -        rfc_attachment[:body].should == "#{headers.join("\n")}\n\nsome example text" +        # 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 = get_fixture_mail('rfc822-attachment.email') +            attributes = MailHandler.get_attachment_attributes(mail) +            attributes.size.should == 2 +            rfc_attachment = attributes[1] +            rfc_attachment[:within_rfc822_subject].should == 'Freedom of Information request' +            headers = ['Date: Thu, 13 Mar 2008 16:57:33 +0000', +                       'Subject: Freedom of Information request', +                       'From: An FOI Officer <foi.officer@example.com>', +                       'To: request-bounce-xx-xxxxx@whatdotheyno.com'] +            rfc_attachment[:body].should == "#{headers.join("\n")}\n\nsome example text" +        end      end      it 'should handle a mail which causes Tmail to generate a blank header value' do diff --git a/spec/lib/timezone_fixes_spec.rb b/spec/lib/timezone_fixes_spec.rb index a2bea5f64..525bd7561 100644 --- a/spec/lib/timezone_fixes_spec.rb +++ b/spec/lib/timezone_fixes_spec.rb @@ -92,22 +92,6 @@ describe "when doing things with timezones" do      end    end - - protected - -    def with_env_tz(new_tz = 'US/Eastern') -      old_tz, ENV['TZ'] = ENV['TZ'], new_tz -      yield -    ensure -      old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') -    end - -    def with_active_record_default_timezone(zone) -      old_zone, ActiveRecord::Base.default_timezone = ActiveRecord::Base.default_timezone, zone -      yield -    ensure -      ActiveRecord::Base.default_timezone = old_zone -    end  end 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4cf376624..561a75da6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -275,3 +275,18 @@ class ApplicationController < ActionController::Base          @popup_banner = nil      end  end + + +def with_env_tz(new_tz = 'US/Eastern') +  old_tz, ENV['TZ'] = ENV['TZ'], new_tz +  yield +ensure +  old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') +end + +def with_active_record_default_timezone(zone) +  old_zone, ActiveRecord::Base.default_timezone = ActiveRecord::Base.default_timezone, zone +  yield +ensure +  ActiveRecord::Base.default_timezone = old_zone +end | 
