Commit 94c9b4117ca2ecdeb21cef76c6b763ea27d7848e
1 parent
01924426
Exists in
master
and in
1 other branch
add test and code for the hubot notification service
Showing
2 changed files
with
51 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,36 @@ |
1 | +class NotificationServices::HubotService < NotificationService | |
2 | + Label = "hubot" | |
3 | + Fields = [ | |
4 | + [:api_token, { | |
5 | + :placeholder => 'http://hubot.example.org:8080/hubot/say', | |
6 | + :label => 'Hubot URL' | |
7 | + }], | |
8 | + [:room_id, { | |
9 | + :placeholder => '#dev', | |
10 | + :label => 'Room where Hubot should notify' | |
11 | + }] | |
12 | + ] | |
13 | + | |
14 | + def check_params | |
15 | + if Fields.detect {|f| self[f[0]].blank? } | |
16 | + errors.add :base, 'You must specify the URL of your hubot' | |
17 | + end | |
18 | + end | |
19 | + | |
20 | + def url | |
21 | + api_token | |
22 | + end | |
23 | + | |
24 | + def message_for_hubot(problem) | |
25 | + notification_description(problem) | |
26 | + end | |
27 | + | |
28 | + def create_notification(problem) | |
29 | + | |
30 | + Faraday.post(url, :message => message_for_hubot(problem), :room => room_id) | |
31 | + # send push notification to pushover | |
32 | + #notification.notify(api_token, "#{notification_description problem}", :priority => 1, :title => "Errbit Notification", :url => "http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}", :url_title => "Link to error") | |
33 | + | |
34 | + end | |
35 | +end | |
36 | + | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe NotificationService::HubotService do | |
4 | + it "it should send a notification to Hubot" do | |
5 | + # setup | |
6 | + notice = Fabricate :notice | |
7 | + notification_service = Fabricate :hubot_notification_service, :app => notice.app | |
8 | + problem = notice.problem | |
9 | + | |
10 | + # faraday stubbing | |
11 | + Faraday.should_receive(:post).with(notification_service.api_token, {:message => '[production][foo#bar] FooError: Too Much Bar', :room => notification_service.room_id}).and_return(true) | |
12 | + | |
13 | + notification_service.create_notification(problem) | |
14 | + end | |
15 | +end | ... | ... |