task_mailer_test.rb
4.08 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
require File.dirname(__FILE__) + '/../test_helper'
class TaskMailerTest < Test::Unit::TestCase
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
CHARSET = "utf-8"
include ActionMailer::Quoting
def setup
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
@expected = TMail::Mail.new
@expected.set_content_type "text", "plain", { "charset" => CHARSET }
@expected.mime_version = '1.0'
end
should 'be able to send a "task finished" message' do
task = Task.new
task.expects(:task_finished_message).returns('the message')
task.expects(:description).returns('the task')
requestor = mock()
requestor.expects(:email).returns('requestor@example.com')
requestor.expects(:name).returns('my name')
environment = mock()
environment.expects(:contact_email).returns('sender@example.com')
environment.expects(:default_hostname).returns('example.com')
environment.expects(:name).returns('example').at_least_once
task.expects(:requestor).returns(requestor).at_least_once
requestor.expects(:environment).returns(environment).at_least_once
TaskMailer.deliver_task_finished(task)
end
should 'be able to send a "task cancelled" message' do
task = Task.new
task.expects(:task_cancelled_message).returns('the message')
task.expects(:description).returns('the task')
requestor = mock()
requestor.expects(:email).returns('requestor@example.com')
requestor.expects(:name).returns('my name')
environment = mock()
environment.expects(:contact_email).returns('sender@example.com')
environment.expects(:default_hostname).returns('example.com')
environment.expects(:name).returns('example').at_least_once
task.expects(:requestor).returns(requestor).at_least_once
requestor.expects(:environment).returns(environment).at_least_once
TaskMailer.deliver_task_cancelled(task)
end
should 'be able to send a "task created" message' do
task = Task.new
task.expects(:task_created_message).returns('the message')
task.expects(:description).returns('the task')
requestor = mock()
requestor.expects(:email).returns('requestor@example.com')
requestor.expects(:name).returns('my name')
environment = mock()
environment.expects(:contact_email).returns('sender@example.com')
environment.expects(:default_hostname).returns('example.com')
environment.expects(:name).returns('example').at_least_once
task.expects(:requestor).returns(requestor).at_least_once
requestor.expects(:environment).returns(environment).at_least_once
TaskMailer.deliver_task_created(task)
end
should 'be able to send a "target notification" message' do
task = Task.new
task.expects(:description).returns('the task')
requestor = mock()
requestor.expects(:name).returns('my name')
target = mock()
target.expects(:contact_email).returns('target@example.com')
target.expects(:name).returns('Target')
environment = mock()
environment.expects(:contact_email).returns('sender@example.com')
environment.expects(:default_hostname).returns('example.com')
environment.expects(:name).returns('example').at_least_once
task.expects(:requestor).returns(requestor).at_least_once
task.expects(:target).returns(target).at_least_once
requestor.expects(:environment).returns(environment).at_least_once
TaskMailer.deliver_target_notification(task, 'the message')
end
should 'use environment name and contact email' do
task = mock
requestor = mock
environment = mock
environment.expects(:name).returns('My name')
environment.expects(:contact_email).returns('email@example.com')
task.expects(:requestor).returns(requestor).at_least_once
requestor.expects(:environment).returns(environment).at_least_once
assert_equal 'My name <email@example.com>', TaskMailer.generate_from(task)
end
private
def read_fixture(action)
IO.readlines("#{FIXTURES_PATH}/task_mailer/#{action}")
end
def encode(subject)
quoted_printable(subject, CHARSET)
end
end