Commit c796a8aa2d1d4f8841a9d4b116010af532879645

Authored by JD Guzman
1 parent 24c65a53
Exists in master and in 1 other branch production

fixing bug, slack complaining of invalid json

app/models/notification_services/slack_service.rb
@@ -32,10 +32,10 @@ class NotificationServices::SlackService < NotificationService @@ -32,10 +32,10 @@ class NotificationServices::SlackService < NotificationService
32 def post_payload(problem) 32 def post_payload(problem)
33 payload = {:text => message_for_slack(problem) } 33 payload = {:text => message_for_slack(problem) }
34 payload[:channel] = room_id unless room_id.empty? 34 payload[:channel] = room_id unless room_id.empty?
35 - payload 35 + payload.to_json
36 end 36 end
37 37
38 def create_notification(problem) 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 end 40 end
41 end 41 end
spec/models/notification_service/slack_service_spec.rb
@@ -8,7 +8,8 @@ describe NotificationService::SlackService do @@ -8,7 +8,8 @@ describe NotificationService::SlackService do
8 problem = notice.problem 8 problem = notice.problem
9 9
10 # faraday stubbing 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 notification_service.create_notification(problem) 14 notification_service.create_notification(problem)
14 end 15 end
@@ -20,7 +21,8 @@ describe NotificationService::SlackService do @@ -20,7 +21,8 @@ describe NotificationService::SlackService do
20 problem = notice.problem 21 problem = notice.problem
21 22
22 # faraday stubbing 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 notification_service.create_notification(problem) 27 notification_service.create_notification(problem)
26 end 28 end