Commit c428b294 authored by Andy Soiron's avatar Andy Soiron Committed by Markus Koller

Fix allow_blank for chat notification validation

Changelog: fixed
parent 5d8d5142
......@@ -30,7 +30,7 @@ class ChatNotificationService < Service
boolean_accessor :notify_only_broken_pipelines, :notify_only_default_branch
validates :webhook, presence: true, public_url: true, if: :activated?
validates :labels_to_be_notified_behavior, inclusion: { in: LABEL_NOTIFICATION_BEHAVIOURS }, allow_nil: true
validates :labels_to_be_notified_behavior, inclusion: { in: LABEL_NOTIFICATION_BEHAVIOURS }, allow_blank: true
def initialize_properties
if properties.nil?
......
---
title: Fix slack label filter behavior blank
merge_request: 61236
author:
type: fixed
......@@ -12,7 +12,7 @@ RSpec.describe ChatNotificationService do
end
describe 'validations' do
it { is_expected.to validate_inclusion_of(:labels_to_be_notified_behavior).in_array(%w[match_any match_all]) }
it { is_expected.to validate_inclusion_of(:labels_to_be_notified_behavior).in_array(%w[match_any match_all]).allow_blank }
end
describe '#can_test?' do
......@@ -127,6 +127,22 @@ RSpec.describe ChatNotificationService do
end
end
context 'when labels_to_be_notified_behavior is blank' do
subject(:chat_service) { described_class.new(labels_to_be_notified: label_filter, labels_to_be_notified_behavior: '') }
context 'no matching labels' do
let(:label_filter) { '~some random label' }
it_behaves_like 'does not notify the chat service'
end
context 'only one label matches' do
let(:label_filter) { '~some random label, ~Bug' }
it_behaves_like 'notifies the chat service'
end
end
context 'when labels_to_be_notified_behavior is match_any' do
subject(:chat_service) do
described_class.new(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment