From 0d4a6e45e17711238acafbc8652cac318ebf8199 Mon Sep 17 00:00:00 2001 From: Stephen Crosby Date: Sun, 28 Feb 2016 15:32:50 -0800 Subject: [PATCH] obey the cops --- app/models/notification_services/slack_service.rb | 6 +++--- spec/models/notification_service/slack_service_spec.rb | 26 ++++++++++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/models/notification_services/slack_service.rb b/app/models/notification_services/slack_service.rb index a30a1f6..a09bbf2 100644 --- a/app/models/notification_services/slack_service.rb +++ b/app/models/notification_services/slack_service.rb @@ -19,8 +19,8 @@ class NotificationServices::SlackService < NotificationService def post_payload(problem) { - username: "Errbit", - icon_emoji: ":collision:", + username: "Errbit", + icon_emoji: ":collision:", attachments: [ { fallback: message_for_slack(problem), @@ -28,7 +28,7 @@ class NotificationServices::SlackService < NotificationService title_link: problem.url, text: problem.where, color: "#D00000", - fields: [ + fields: [ { title: "Application", value: problem.app.name, diff --git a/spec/models/notification_service/slack_service_spec.rb b/spec/models/notification_service/slack_service_spec.rb index 1df9a31..ebe4039 100644 --- a/spec/models/notification_service/slack_service_spec.rb +++ b/spec/models/notification_service/slack_service_spec.rb @@ -1,24 +1,30 @@ describe NotificationServices::SlackService, type: 'model' do + let(:notice) { Fabricate :notice } + let(:service_url) do + "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX" + end + + let(:service) do + Fabricate :slack_notification_service, app: notice.app, + service_url: service_url + end + it "it should send a notification to Slack with hook url" do # setup - notice = Fabricate :notice - notification_service = Fabricate :slack_notification_service, - app: notice.app, - service_url: "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX" problem = notice.problem # faraday stubbing payload = { - username: "Errbit", - icon_emoji: ":collision:", + username: "Errbit", + icon_emoji: ":collision:", attachments: [ { - fallback: notification_service.message_for_slack(problem), + fallback: service.message_for_slack(problem), title: problem.message.to_s.truncate(100), title_link: problem.url, text: problem.where, color: "#D00000", - fields: [ + fields: [ { title: "Application", value: problem.app.name, @@ -43,8 +49,8 @@ describe NotificationServices::SlackService, type: 'model' do } ] }.to_json - expect(HTTParty).to receive(:post).with(notification_service.service_url, body: payload, headers: { "Content-Type" => "application/json" }).and_return(true) + expect(HTTParty).to receive(:post).with(service.service_url, body: payload, headers: { "Content-Type" => "application/json" }).and_return(true) - notification_service.create_notification(problem) + service.create_notification(problem) end end -- libgit2 0.21.2