From 63a2356d6383f8f90a6b2eae433a9b29370e9525 Mon Sep 17 00:00:00 2001 From: Ryan Jones Date: Tue, 14 Aug 2012 15:54:36 -0600 Subject: [PATCH] added tests --- app/models/notice_observer.rb | 3 ++- spec/controllers/errs_controller_spec.rb | 8 -------- spec/models/notice_observer_spec.rb | 12 +++++++----- spec/models/notification_service/campfire_service_spec.rb | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 spec/models/notification_service/campfire_service_spec.rb diff --git a/app/models/notice_observer.rb b/app/models/notice_observer.rb index 2fbb5ea..4bef58d 100644 --- a/app/models/notice_observer.rb +++ b/app/models/notice_observer.rb @@ -16,8 +16,9 @@ class NoticeObserver < Mongoid::Observer def should_notify? notice app = notice.app - app.notify_on_errs? && + a = app.notify_on_errs? && (Errbit::Config.per_app_email_at_notices && app.email_at_notices || Errbit::Config.email_at_notices).include?(notice.problem.notices_count) && app.notification_recipients.any? + a end end diff --git a/spec/controllers/errs_controller_spec.rb b/spec/controllers/errs_controller_spec.rb index 9fe7c32..33a8136 100644 --- a/spec/controllers/errs_controller_spec.rb +++ b/spec/controllers/errs_controller_spec.rb @@ -188,14 +188,6 @@ describe ErrsController do response.body.should_not button_matcher end - it "should not exist for err's app with campfire" do - tracker = Fabricate(:campfire_tracker) - err = Fabricate(:err, :problem => Fabricate(:problem, :app => tracker.app)) - get :show, :app_id => err.app.id, :id => err.problem.id - - response.body.should_not button_matcher - end - it "should exist for err's app with issue tracker" do tracker = Fabricate(:lighthouse_tracker) err = Fabricate(:err, :problem => Fabricate(:problem, :app => tracker.app)) diff --git a/spec/models/notice_observer_spec.rb b/spec/models/notice_observer_spec.rb index 24f6bb5..e653302 100644 --- a/spec/models/notice_observer_spec.rb +++ b/spec/models/notice_observer_spec.rb @@ -44,7 +44,7 @@ describe NoticeObserver do end describe "should send a notification if a notification service is configured" do - let(:app) { Fabricate(:app, :email_at_notices => [1], :notification_service => Fabricate(:campfire_notification_service)) } + let(:app) { app = Fabricate(:app, :email_at_notices => [1], :notification_service => Fabricate(:campfire_notification_service))} let(:err) { Fabricate(:err, :problem => Fabricate(:problem, :app => app, :notices_count => 100)) } before do @@ -56,11 +56,13 @@ describe NoticeObserver do end it "should create a campfire notification" do - pending "not working yet" - #err.problem.stub(:notices_count).and_return(1) - #app.notification_service.stub!(:create_notification).and_return(true) - #app.notification_service.should_receive(:create_notification) + err.problem.stub(:notices_count) { 1 } + app.notification_service.stub!(:create_notification).and_return(true) + app.stub!(:notification_recipients => %w('ryan@system88.com')) + app.notification_service.should_receive(:create_notification) + Notice.create!(:err => err, :message => 'FooError: Too Much Bar', :server_environment => {'environment-name' => 'production'}, + :backtrace => [{ :error => 'Le Broken' }], :notifier => { 'name' => 'Notifier', 'version' => '1', 'url' => 'http://toad.com' }) end end diff --git a/spec/models/notification_service/campfire_service_spec.rb b/spec/models/notification_service/campfire_service_spec.rb new file mode 100644 index 0000000..5f61f5c --- /dev/null +++ b/spec/models/notification_service/campfire_service_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe NotificationService::CampfireService do + it "it should send a notification to campfire" do + # setup + notice = Fabricate :notice + notification_service = Fabricate :campfire_notification_service, :app => notice.app + problem = notice.problem + + #campy stubbing + campy = mock('CampfireService') + Campy::Room.stub(:new).and_return(campy) + campy.stub(:speak) { true } + + #assert + campy.should_receive(:speak) + + notification_service.create_notification(problem) + end +end + -- libgit2 0.21.2