File: parts_list_spec.rb

package info (click to toggle)
ruby-mail 2.6.4%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,256 kB
  • ctags: 1,327
  • sloc: ruby: 44,678; makefile: 3
file content (75 lines) | stat: -rw-r--r-- 1,792 bytes parent folder | download
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# encoding: utf-8
# frozen_string_literal: true

require 'spec_helper'

describe "PartsList" do
  it "should return itself on sort" do
    p = Mail::PartsList.new
    p << 2
    p << 1
    expect(p.sort.class).to eq Mail::PartsList
  end

  it "should not fail if we do not have a content_type" do
    p = Mail::PartsList.new
    order = ['text/plain']
    p << 'text/plain'
    p << 'text/html'
    p.sort!(order)
  end

  it "should not fail if we do not have a content_type" do
    p = Mail::PartsList.new
    order = ['text/plain', 'text/html']

    no_content_type_part = Mail::Part.new
    plain_text_part      = Mail::Part.new
    html_text_part       = Mail::Part.new

    no_content_type_part.content_type = nil
    html_text_part.content_type       = 'text/html'

    p << no_content_type_part
    p << plain_text_part
    p << html_text_part
    expect(p.sort!(order)).to eq [plain_text_part, html_text_part, no_content_type_part]
  end

  it "should have a parts reader" do
    p = Mail::PartsList.new([1, 2])
    expect(p.parts).to eq([1, 2])
  end

  it "should behave like an array" do
    p = Mail::PartsList.new([1, 2])
    expect(p.first).to eq(1)
  end

  it "is equal to itself" do
    p = Mail::PartsList.new([1, 2])
    expect(p).to eq(p)
  end

  it "is equal to its parts array" do
    p = Mail::PartsList.new
    p << "foo"
    p << "bar"
    expect(p).to eq(["foo", "bar"])
  end

  it "can be mixed with an array" do
    p = Mail::PartsList.new([3, 4])
    expect([1, 2] + p).to eq [1, 2, 3, 4]
  end

  it "should respond to Array methods" do
    p = Mail::PartsList.new
    expect(p).to respond_to(:reduce)
  end

  it "should have a round-tripping YAML serialization" do
    p = Mail::PartsList.new([1, 2])
    expect(YAML.load(YAML.dump(p))).to eq(p)
  end
end