Commit 0d4a6e45e17711238acafbc8652cac318ebf8199
1 parent
70d21539
Exists in
master
obey the cops
Showing
2 changed files
with
19 additions
and
13 deletions
Show diff stats
app/models/notification_services/slack_service.rb
... | ... | @@ -19,8 +19,8 @@ class NotificationServices::SlackService < NotificationService |
19 | 19 | |
20 | 20 | def post_payload(problem) |
21 | 21 | { |
22 | - username: "Errbit", | |
23 | - icon_emoji: ":collision:", | |
22 | + username: "Errbit", | |
23 | + icon_emoji: ":collision:", | |
24 | 24 | attachments: [ |
25 | 25 | { |
26 | 26 | fallback: message_for_slack(problem), |
... | ... | @@ -28,7 +28,7 @@ class NotificationServices::SlackService < NotificationService |
28 | 28 | title_link: problem.url, |
29 | 29 | text: problem.where, |
30 | 30 | color: "#D00000", |
31 | - fields: [ | |
31 | + fields: [ | |
32 | 32 | { |
33 | 33 | title: "Application", |
34 | 34 | value: problem.app.name, | ... | ... |
spec/models/notification_service/slack_service_spec.rb
1 | 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 | 12 | it "it should send a notification to Slack with hook url" do |
3 | 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 | 14 | problem = notice.problem |
9 | 15 | |
10 | 16 | # faraday stubbing |
11 | 17 | payload = { |
12 | - username: "Errbit", | |
13 | - icon_emoji: ":collision:", | |
18 | + username: "Errbit", | |
19 | + icon_emoji: ":collision:", | |
14 | 20 | attachments: [ |
15 | 21 | { |
16 | - fallback: notification_service.message_for_slack(problem), | |
22 | + fallback: service.message_for_slack(problem), | |
17 | 23 | title: problem.message.to_s.truncate(100), |
18 | 24 | title_link: problem.url, |
19 | 25 | text: problem.where, |
20 | 26 | color: "#D00000", |
21 | - fields: [ | |
27 | + fields: [ | |
22 | 28 | { |
23 | 29 | title: "Application", |
24 | 30 | value: problem.app.name, |
... | ... | @@ -43,8 +49,8 @@ describe NotificationServices::SlackService, type: 'model' do |
43 | 49 | } |
44 | 50 | ] |
45 | 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 | 55 | end |
50 | 56 | end | ... | ... |