From 52c8651a6caf5236ff173555164b676958540b9e Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 8 May 2017 12:00:30 +1000 Subject: Fix notify_only_default_branch check for Slack service The notify_only_default_branch property is using boolean_accessor this means we need to check it using a question methods. Also add specs for disabling this option. --- app/models/project_services/chat_notification_service.rb | 2 +- changelogs/unreleased/mrchrisw-fix-slack-notify.yml | 4 ++++ .../slack_mattermost_notifications_shared_examples.rb | 14 +++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/mrchrisw-fix-slack-notify.yml diff --git a/app/models/project_services/chat_notification_service.rb b/app/models/project_services/chat_notification_service.rb index fa782c6fbb7..6464bf3f4a4 100644 --- a/app/models/project_services/chat_notification_service.rb +++ b/app/models/project_services/chat_notification_service.rb @@ -150,7 +150,7 @@ class ChatNotificationService < Service def notify_for_ref?(data) return true if data[:object_attributes][:tag] - return true unless notify_only_default_branch + return true unless notify_only_default_branch? data[:object_attributes][:ref] == project.default_branch end diff --git a/changelogs/unreleased/mrchrisw-fix-slack-notify.yml b/changelogs/unreleased/mrchrisw-fix-slack-notify.yml new file mode 100644 index 00000000000..bb45a117be6 --- /dev/null +++ b/changelogs/unreleased/mrchrisw-fix-slack-notify.yml @@ -0,0 +1,4 @@ +--- +title: Fix notify_only_default_branch check for Slack service +merge_request: +author: diff --git a/spec/support/slack_mattermost_notifications_shared_examples.rb b/spec/support/slack_mattermost_notifications_shared_examples.rb index b902fe90707..7e35ebb6c97 100644 --- a/spec/support/slack_mattermost_notifications_shared_examples.rb +++ b/spec/support/slack_mattermost_notifications_shared_examples.rb @@ -328,7 +328,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do context 'only notify for the default branch' do context 'when enabled' do let(:pipeline) do - create(:ci_pipeline, project: project, status: 'failed', ref: 'not-the-default-branch') + create(:ci_pipeline, :failed, project: project, ref: 'not-the-default-branch') end before do @@ -342,6 +342,18 @@ RSpec.shared_examples 'slack or mattermost notifications' do expect(result).to be_falsy end end + + context 'when disabled' do + let(:pipeline) do + create(:ci_pipeline, :failed, project: project, ref: 'not-the-default-branch') + end + + before do + chat_service.notify_only_default_branch = false + end + + it_behaves_like 'call Slack/Mattermost API' + end end end end -- cgit v1.2.1