Commit 0d4a6e45e17711238acafbc8652cac318ebf8199

Authored by Stephen Crosby
1 parent 70d21539
Exists in master

obey the cops

app/models/notification_services/slack_service.rb
@@ -19,8 +19,8 @@ class NotificationServices::SlackService < NotificationService @@ -19,8 +19,8 @@ class NotificationServices::SlackService < NotificationService
19 19
20 def post_payload(problem) 20 def post_payload(problem)
21 { 21 {
22 - username: "Errbit",  
23 - icon_emoji: ":collision:", 22 + username: "Errbit",
  23 + icon_emoji: ":collision:",
24 attachments: [ 24 attachments: [
25 { 25 {
26 fallback: message_for_slack(problem), 26 fallback: message_for_slack(problem),
@@ -28,7 +28,7 @@ class NotificationServices::SlackService < NotificationService @@ -28,7 +28,7 @@ class NotificationServices::SlackService < NotificationService
28 title_link: problem.url, 28 title_link: problem.url,
29 text: problem.where, 29 text: problem.where,
30 color: "#D00000", 30 color: "#D00000",
31 - fields: [ 31 + fields: [
32 { 32 {
33 title: "Application", 33 title: "Application",
34 value: problem.app.name, 34 value: problem.app.name,
spec/models/notification_service/slack_service_spec.rb
1 describe NotificationServices::SlackService, type: 'model' do 1 describe NotificationServices::SlackService, type: 'model' do
  2 + let(:notice) { Fabricate :notice }
  3 + let(:service_url) do
  4 + "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX"
  5 + end
  6 +
  7 + let(:service) do
  8 + Fabricate :slack_notification_service, app: notice.app,
  9 + service_url: service_url
  10 + end
  11 +
2 it "it should send a notification to Slack with hook url" do 12 it "it should send a notification to Slack with hook url" do
3 # setup 13 # setup
4 - notice = Fabricate :notice  
5 - notification_service = Fabricate :slack_notification_service,  
6 - app: notice.app,  
7 - service_url: "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX"  
8 problem = notice.problem 14 problem = notice.problem
9 15
10 # faraday stubbing 16 # faraday stubbing
11 payload = { 17 payload = {
12 - username: "Errbit",  
13 - icon_emoji: ":collision:", 18 + username: "Errbit",
  19 + icon_emoji: ":collision:",
14 attachments: [ 20 attachments: [
15 { 21 {
16 - fallback: notification_service.message_for_slack(problem), 22 + fallback: service.message_for_slack(problem),
17 title: problem.message.to_s.truncate(100), 23 title: problem.message.to_s.truncate(100),
18 title_link: problem.url, 24 title_link: problem.url,
19 text: problem.where, 25 text: problem.where,
20 color: "#D00000", 26 color: "#D00000",
21 - fields: [ 27 + fields: [
22 { 28 {
23 title: "Application", 29 title: "Application",
24 value: problem.app.name, 30 value: problem.app.name,
@@ -43,8 +49,8 @@ describe NotificationServices::SlackService, type: 'model' do @@ -43,8 +49,8 @@ describe NotificationServices::SlackService, type: 'model' do
43 } 49 }
44 ] 50 ]
45 }.to_json 51 }.to_json
46 - expect(HTTParty).to receive(:post).with(notification_service.service_url, body: payload, headers: { "Content-Type" => "application/json" }).and_return(true) 52 + expect(HTTParty).to receive(:post).with(service.service_url, body: payload, headers: { "Content-Type" => "application/json" }).and_return(true)
47 53
48 - notification_service.create_notification(problem) 54 + service.create_notification(problem)
49 end 55 end
50 end 56 end