mailer_spec.rb
3.42 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
shared_examples "a notification email" do
it "should have X-Mailer header" do
expect(email).to have_header('X-Mailer', 'Errbit')
end
it "should have X-Errbit-Host header" do
expect(email).to have_header('X-Errbit-Host', Errbit::Config.host)
end
it "should have Precedence header" do
expect(email).to have_header('Precedence', 'bulk')
end
it "should have Auto-Submitted header" do
expect(email).to have_header('Auto-Submitted', 'auto-generated')
end
it "should have X-Auto-Response-Suppress header" do
# http://msdn.microsoft.com/en-us/library/ee219609(v=EXCHG.80).aspx
expect(email).to have_header('X-Auto-Response-Suppress', 'OOF, AutoReply')
end
it "should send the email" do
email
expect(ActionMailer::Base.deliveries.size).to eq 1
end
end
describe Mailer do
context "Err Notification" do
include EmailSpec::Helpers
include EmailSpec::Matchers
let(:notice) do
n = Fabricate(:notice, message: "class < ActionController::Base")
n.backtrace.lines.last[:file] = '[PROJECT_ROOT]/path/to/file.js'
# notice.backtrace.update_attributes(lines: lines)
n
end
let(:app) do
a = notice.app
a.update_attributes(
asset_host: "http://example.com",
notify_all_users: true
)
a
end
let(:problem) do
p = notice.problem
p.notices_count = 3
p
end
let!(:user) { Fabricate(:admin) }
let(:error_report) do
instance_double(
'ErrorReport',
notice: notice,
app: app,
problem: problem
)
end
let(:email) do
Mailer.err_notification(error_report).deliver_now
end
before { email }
it_should_behave_like "a notification email"
it "should html-escape the notice's message for the html part" do
expect(email).to have_body_text("class < ActionController::Base")
end
it "should have inline css" do
expect(email).to have_body_text('<p class="backtrace" style="')
end
it "should have links to source files" do
expect(email).to have_body_text('<a target="_blank" href="http://example.com/path/to/file.js">path/to/file.js')
end
it "should have the error count in the subject" do
expect(email.subject).to match(/^\(3\) /)
end
context 'with a very long message' do
let(:notice) { Fabricate(:notice, message: 6.times.collect { |_a| "0123456789" }.join('')) }
it "should truncate the long message" do
expect(email.subject).to match(/ \d{47}\.{3}$/)
end
end
end
context "Comment Notification" do
include EmailSpec::Helpers
include EmailSpec::Matchers
let!(:notice) { Fabricate(:notice) }
let!(:comment) { Fabricate(:comment, err: notice.problem) }
let!(:watcher) { Fabricate(:watcher, app: comment.app) }
let(:recipients) { ['recipient@example.com', 'another@example.com'] }
before do
expect(comment).to receive(:notification_recipients).and_return(recipients)
Fabricate(:notice, err: notice.err)
@email = Mailer.comment_notification(comment).deliver_now
end
it "should be sent to comment notification recipients" do
expect(@email.to).to eq recipients
end
it "should have the notices count in the body" do
expect(@email).to have_body_text("This error has occurred 2 times")
end
it "should have the comment body" do
expect(@email).to have_body_text(comment.body)
end
end
end