File: round_tripping_spec.rb

package info (click to toggle)
ruby-mail 2.6.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,092 kB
  • ctags: 1,281
  • sloc: ruby: 43,919; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,706 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# encoding: utf-8
require 'spec_helper'

describe "Round Tripping" do

  it "should round trip a basic email" do
    mail = Mail.new('Subject: FooBar')
    mail.body "This is Text"
    parsed_mail = Mail.new(mail.to_s)
    parsed_mail.subject.to_s.should eq "FooBar"
    parsed_mail.body.to_s.should eq "This is Text"
  end

  it "should round trip a html multipart email" do
    mail = Mail.new('Subject: FooBar')
    mail.text_part = Mail::Part.new do
      body "This is Text"
    end
    mail.html_part = Mail::Part.new do
      content_type "text/html; charset=US-ASCII"
      body "<b>This is HTML</b>"
    end
    parsed_mail = Mail.new(mail.to_s)
    parsed_mail.mime_type.should eq 'multipart/alternative'
    parsed_mail.boundary.should eq mail.boundary
    parsed_mail.parts.length.should eq 2
    parsed_mail.parts[0].body.to_s.should eq "This is Text"
    parsed_mail.parts[1].body.to_s.should eq "<b>This is HTML</b>"
  end

  it "should round trip an email" do
    initial = Mail.new do
      to        "mikel@test.lindsaar.net"
      subject   "testing round tripping"
      body      "Really testing round tripping."
      from      "system@test.lindsaar.net"
      cc        "nobody@test.lindsaar.net"
      bcc       "bob@test.lindsaar.net"
      date      Time.local(2009, 11, 6)
      add_file  :filename => "foo.txt", :content => "I have \ntwo lines\n\n"
    end
    Mail.new(initial.encoded).encoded.should eq initial.encoded
  end

  it "should round trip attachment newlines" do
    body = "I have \ntwo lines\n\n"
    initial = Mail.new
    initial.add_file :filename => "foo.txt", :content => body
    Mail.new(initial.encoded).attachments.first.decoded.should eq body
  end
end