Commit 63a2356d6383f8f90a6b2eae433a9b29370e9525

Authored by Ryan Jones
1 parent 04f3d76b
Exists in master and in 1 other branch production

added tests

app/models/notice_observer.rb
... ... @@ -16,8 +16,9 @@ class NoticeObserver < Mongoid::Observer
16 16  
17 17 def should_notify? notice
18 18 app = notice.app
19   - app.notify_on_errs? &&
  19 + a = app.notify_on_errs? &&
20 20 (Errbit::Config.per_app_email_at_notices && app.email_at_notices || Errbit::Config.email_at_notices).include?(notice.problem.notices_count) &&
21 21 app.notification_recipients.any?
  22 + a
22 23 end
23 24 end
... ...
spec/controllers/errs_controller_spec.rb
... ... @@ -188,14 +188,6 @@ describe ErrsController do
188 188 response.body.should_not button_matcher
189 189 end
190 190  
191   - it "should not exist for err's app with campfire" do
192   - tracker = Fabricate(:campfire_tracker)
193   - err = Fabricate(:err, :problem => Fabricate(:problem, :app => tracker.app))
194   - get :show, :app_id => err.app.id, :id => err.problem.id
195   -
196   - response.body.should_not button_matcher
197   - end
198   -
199 191 it "should exist for err's app with issue tracker" do
200 192 tracker = Fabricate(:lighthouse_tracker)
201 193 err = Fabricate(:err, :problem => Fabricate(:problem, :app => tracker.app))
... ...
spec/models/notice_observer_spec.rb
... ... @@ -44,7 +44,7 @@ describe NoticeObserver do
44 44 end
45 45  
46 46 describe "should send a notification if a notification service is configured" do
47   - let(:app) { Fabricate(:app, :email_at_notices => [1], :notification_service => Fabricate(:campfire_notification_service)) }
  47 + let(:app) { app = Fabricate(:app, :email_at_notices => [1], :notification_service => Fabricate(:campfire_notification_service))}
48 48 let(:err) { Fabricate(:err, :problem => Fabricate(:problem, :app => app, :notices_count => 100)) }
49 49  
50 50 before do
... ... @@ -56,11 +56,13 @@ describe NoticeObserver do
56 56 end
57 57  
58 58 it "should create a campfire notification" do
59   - pending "not working yet"
60   - #err.problem.stub(:notices_count).and_return(1)
61   - #app.notification_service.stub!(:create_notification).and_return(true)
62   - #app.notification_service.should_receive(:create_notification)
  59 + err.problem.stub(:notices_count) { 1 }
  60 + app.notification_service.stub!(:create_notification).and_return(true)
  61 + app.stub!(:notification_recipients => %w('ryan@system88.com'))
  62 + app.notification_service.should_receive(:create_notification)
63 63  
  64 + Notice.create!(:err => err, :message => 'FooError: Too Much Bar', :server_environment => {'environment-name' => 'production'},
  65 + :backtrace => [{ :error => 'Le Broken' }], :notifier => { 'name' => 'Notifier', 'version' => '1', 'url' => 'http://toad.com' })
64 66 end
65 67 end
66 68  
... ...
spec/models/notification_service/campfire_service_spec.rb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +require 'spec_helper'
  2 +
  3 +describe NotificationService::CampfireService do
  4 + it "it should send a notification to campfire" do
  5 + # setup
  6 + notice = Fabricate :notice
  7 + notification_service = Fabricate :campfire_notification_service, :app => notice.app
  8 + problem = notice.problem
  9 +
  10 + #campy stubbing
  11 + campy = mock('CampfireService')
  12 + Campy::Room.stub(:new).and_return(campy)
  13 + campy.stub(:speak) { true }
  14 +
  15 + #assert
  16 + campy.should_receive(:speak)
  17 +
  18 + notification_service.create_notification(problem)
  19 + end
  20 +end
  21 +
... ...