notice_spec.rb
3.71 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
require 'spec_helper'
describe Notice do
context 'validations' do
it 'requires a backtrace' do
notice = Factory.build(:notice, :backtrace => nil)
notice.should_not be_valid
notice.errors[:backtrace].should include("can't be blank")
end
it 'requires the server_environment' do
notice = Factory.build(:notice, :server_environment => nil)
notice.should_not be_valid
notice.errors[:server_environment].should include("can't be blank")
end
it 'requires the notifier' do
notice = Factory.build(:notice, :notifier => nil)
notice.should_not be_valid
notice.errors[:notifier].should include("can't be blank")
end
end
context '#from_xml' do
before do
@xml = Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read
@app = Factory(:app, :api_key => 'APIKEY')
Digest::MD5.stub(:hexdigest).and_return('fingerprintdigest')
end
it 'finds the correct app' do
@notice = Notice.from_xml(@xml)
@notice.err.app.should == @app
end
it 'finds the correct err for the notice' do
Err.should_receive(:for).with({
:app => @app,
:klass => 'HoptoadTestingException',
:component => 'application',
:action => 'verify',
:environment => 'development',
:fingerprint => 'fingerprintdigest'
}).and_return(err = Factory(:err))
err.notices.stub(:create!)
@notice = Notice.from_xml(@xml)
end
it 'marks the err as unresolve if it was previously resolved' do
Err.should_receive(:for).with({
:app => @app,
:klass => 'HoptoadTestingException',
:component => 'application',
:action => 'verify',
:environment => 'development',
:fingerprint => 'fingerprintdigest'
}).and_return(err = Factory(:err, :resolved => true))
err.should be_resolved
@notice = Notice.from_xml(@xml)
@notice.err.should == err
@notice.err.should_not be_resolved
end
it 'should create a new notice' do
@notice = Notice.from_xml(@xml)
@notice.should be_persisted
end
it 'assigns an err to the notice' do
@notice = Notice.from_xml(@xml)
@notice.err.should be_a(Err)
end
it 'captures the err message' do
@notice = Notice.from_xml(@xml)
@notice.message.should == 'HoptoadTestingException: Testing hoptoad via "rake hoptoad:test". If you can see this, it works.'
end
it 'captures the backtrace' do
@notice = Notice.from_xml(@xml)
@notice.backtrace.size.should == 73
@notice.backtrace.last['file'].should == '[GEM_ROOT]/bin/rake'
end
it 'captures the server_environment' do
@notice = Notice.from_xml(@xml)
@notice.server_environment['environment-name'].should == 'development'
end
it 'captures the request' do
@notice = Notice.from_xml(@xml)
@notice.request['url'].should == 'http://example.org/verify'
@notice.request['params']['controller'].should == 'application'
end
it 'captures the notifier' do
@notice = Notice.from_xml(@xml)
@notice.notifier['name'].should == 'Hoptoad Notifier'
end
end
describe "email notifications" do
before do
@app = Factory(:app_with_watcher)
@err = Factory(:err, :app => @app)
end
Errbit::Config.email_at_notices.each do |threshold|
it "sends an email notification after #{threshold} notice(s)" do
@err.notices.stub(:count).and_return(threshold)
Mailer.should_receive(:err_notification).
and_return(mock('email', :deliver => true))
Factory(:notice, :err => @err)
end
end
end
end