Commit c796a8aa2d1d4f8841a9d4b116010af532879645
1 parent
24c65a53
Exists in
master
and in
1 other branch
fixing bug, slack complaining of invalid json
Showing
2 changed files
with
6 additions
and
4 deletions
Show diff stats
app/models/notification_services/slack_service.rb
... | ... | @@ -32,10 +32,10 @@ class NotificationServices::SlackService < NotificationService |
32 | 32 | def post_payload(problem) |
33 | 33 | payload = {:text => message_for_slack(problem) } |
34 | 34 | payload[:channel] = room_id unless room_id.empty? |
35 | - payload | |
35 | + payload.to_json | |
36 | 36 | end |
37 | 37 | |
38 | 38 | def create_notification(problem) |
39 | - HTTParty.post(url, :body => {:payload => post_payload(problem)}) | |
39 | + HTTParty.post(url, :body => post_payload(problem), :headers => { 'Content-Type' => 'application/json' }) | |
40 | 40 | end |
41 | 41 | end | ... | ... |
spec/models/notification_service/slack_service_spec.rb
... | ... | @@ -8,7 +8,8 @@ describe NotificationService::SlackService do |
8 | 8 | problem = notice.problem |
9 | 9 | |
10 | 10 | # faraday stubbing |
11 | - expect(HTTParty).to receive(:post).with(notification_service.url, :body => {:payload => {:text => an_instance_of(String), :channel => notification_service.room_id}}).and_return(true) | |
11 | + payload = {:text => notification_service.message_for_slack(problem), :channel => notification_service.room_id}.to_json | |
12 | + expect(HTTParty).to receive(:post).with(notification_service.url, :body => payload, :headers => {"Content-Type" => "application/json"}).and_return(true) | |
12 | 13 | |
13 | 14 | notification_service.create_notification(problem) |
14 | 15 | end |
... | ... | @@ -20,7 +21,8 @@ describe NotificationService::SlackService do |
20 | 21 | problem = notice.problem |
21 | 22 | |
22 | 23 | # faraday stubbing |
23 | - expect(HTTParty).to receive(:post).with(notification_service.url, :body => {:payload => {:text => an_instance_of(String)}}).and_return(true) | |
24 | + payload = {:text => notification_service.message_for_slack(problem)}.to_json | |
25 | + expect(HTTParty).to receive(:post).with(notification_service.url, :body => payload, :headers => {"Content-Type" => "application/json"}).and_return(true) | |
24 | 26 | |
25 | 27 | notification_service.create_notification(problem) |
26 | 28 | end | ... | ... |