From f16e413d47af55af253f74b30e03adb5e9e21495 Mon Sep 17 00:00:00 2001 From: Patrick Veverka Date: Tue, 19 May 2015 10:06:57 -0400 Subject: [PATCH] Copy pasted wrong --- spec/models/notification_service/slack_service_spec.rb | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/spec/models/notification_service/slack_service_spec.rb b/spec/models/notification_service/slack_service_spec.rb index 1f00d03..4b47332 100644 --- a/spec/models/notification_service/slack_service_spec.rb +++ b/spec/models/notification_service/slack_service_spec.rb @@ -1,28 +1,16 @@ -class NotificationServices::SlackService < NotificationService - Label = "slack" - Fields += [ - [:service_url, { - :placeholder => 'Slack Hook URL (https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX)', - :label => 'Hook URL' - }] - ] +describe NotificationService::SlackService, type: 'model' do + 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 - def check_params - if Fields.detect {|f| self[f[0]].blank? } - errors.add :base, "You must specify your Slack Hook url." - end - end - - def message_for_slack(problem) - "[#{problem.app.name}][#{problem.environment}][#{problem.where}]: #{problem.error_class} #{problem_url(problem)}" - end - - def post_payload(problem) - { + # faraday stubbing + payload = { :attachments => [ { - :fallback => message_for_slack(problem), - :pretext => "<#{problem_url(problem)}|Errbit - #{problem.app.name}: #{problem.error_class}>", + :fallback => notification_service.message_for_slack(problem), + :pretext => "<#{notification_service.problem_url(problem)}|Errbit - #{problem.app.name}: #{problem.error_class}>", :color => "#D00000", :fields => [ { @@ -59,13 +47,8 @@ class NotificationServices::SlackService < NotificationService } ] }.to_json - end - - def create_notification(problem) - HTTParty.post(service_url, :body => post_payload(problem), :headers => { 'Content-Type' => 'application/json' }) - end + expect(HTTParty).to receive(:post).with(notification_service.service_url, :body => payload, :headers => {"Content-Type" => "application/json"}).and_return(true) - def configured? - service_url.present? + notification_service.create_notification(problem) end end -- libgit2 0.21.2