Commit 241fa8b95f57080dfaf7aeba67abe03cd9b726d7
1 parent
d005c47e
Exists in
master
and in
1 other branch
Notice Observer spec
Showing
2 changed files
with
43 additions
and
2 deletions
Show diff stats
spec/models/notice_observer_spec.rb
1 | require 'spec_helper' | 1 | require 'spec_helper' |
2 | 2 | ||
3 | +describe NoticeObserver do | ||
4 | + describe "email notifications (configured individually for each app)" do | ||
5 | + custom_thresholds = [2, 4, 8, 16, 32, 64] | ||
3 | 6 | ||
7 | + before do | ||
8 | + Errbit::Config.per_app_email_at_notices = true | ||
9 | + @app = Fabricate(:app_with_watcher, :email_at_notices => custom_thresholds) | ||
10 | + @err = Fabricate(:err, :problem => Fabricate(:problem, :app => @app)) | ||
11 | + end | ||
12 | + | ||
13 | + after do | ||
14 | + Errbit::Config.per_app_email_at_notices = false | ||
15 | + end | ||
16 | + | ||
17 | + custom_thresholds.each do |threshold| | ||
18 | + it "sends an email notification after #{threshold} notice(s)" do | ||
19 | + @err.problem.stub(:notices_count).and_return(threshold) | ||
20 | + Mailer.should_receive(:err_notification). | ||
21 | + and_return(mock('email', :deliver => true)) | ||
22 | + Fabricate(:notice, :err => @err) | ||
23 | + end | ||
24 | + end | ||
25 | + end | ||
26 | + | ||
27 | + describe "email notifications for a resolved issue" do | ||
28 | + | ||
29 | + before do | ||
30 | + Errbit::Config.per_app_email_at_notices = true | ||
31 | + @app = Fabricate(:app_with_watcher, :email_at_notices => [1]) | ||
32 | + @err = Fabricate(:err, :problem => Fabricate(:problem, :app => @app, :notices_count => 100)) | ||
33 | + end | ||
34 | + | ||
35 | + after do | ||
36 | + Errbit::Config.per_app_email_at_notices = false | ||
37 | + end | ||
38 | + | ||
39 | + it "should send email notification after 1 notice since an error has been resolved" do | ||
40 | + @err.problem.resolve! | ||
41 | + Mailer.should_receive(:err_notification). | ||
42 | + and_return(mock('email', :deliver => true)) | ||
43 | + Fabricate(:notice, :err => @err) | ||
44 | + end | ||
45 | + end | ||
46 | +end |
spec/models/notice_spec.rb
@@ -109,7 +109,5 @@ describe Notice do | @@ -109,7 +109,5 @@ describe Notice do | ||
109 | notice = Fabricate.build(:notice, :request => {}) | 109 | notice = Fabricate.build(:notice, :request => {}) |
110 | notice.host.should == 'N/A' | 110 | notice.host.should == 'N/A' |
111 | end | 111 | end |
112 | - | ||
113 | end | 112 | end |
114 | - | ||
115 | end | 113 | end |