Commit 6d549a2c authored by Vitali Tatarintev's avatar Vitali Tatarintev

Extract `alerts_service_activated?` into `Project`

Remove duplication by extracting check for active alerts service into
the Project model
parent 1ebbf2cb
......@@ -2286,6 +2286,10 @@ class Project < ApplicationRecord
end
end
def alerts_service_activated?
feature_available?(:incident_management) && alerts_service.try(:active?)
end
private
def closest_namespace_setting(name)
......
......@@ -135,7 +135,7 @@ module EE
private
def update_generic_alert_issue_if_applicable
return unless has_default_generic_alert_title? && alerts_service_activated?
return unless has_default_generic_alert_title? && project.alerts_service_activated?
update_column(:title, "#{title} #{id}")
end
......@@ -143,14 +143,5 @@ module EE
def has_default_generic_alert_title?
title == ::Gitlab::Alerting::NotificationPayloadParser::DEFAULT_TITLE
end
def incident_management_available?
project.feature_available?(:incident_management)
end
def alerts_service_activated?
incident_management_available? &&
project.alerts_service.try(:active?)
end
end
end
......@@ -18,16 +18,7 @@ module Projects
private
delegate :alerts_service, to: :project
def incident_management_available?
project.feature_available?(:incident_management)
end
def alerts_service_activated?
incident_management_available? &&
alerts_service.try(:active?)
end
delegate :alerts_service, :alerts_service_activated?, to: :project
def process_incident_issues
IncidentManagement::ProcessAlertWorker
......
......@@ -14,31 +14,21 @@ describe Issue do
context 'when issue title is "New: Incident"' do
let(:issue) { build(:issue, project: project, title: 'New: Incident') }
context 'when incident management available' do
context 'when alerts service is active' do
before do
stub_licensed_features(incident_management: true)
allow(project).to receive(:alerts_service_activated?).and_return(true)
end
context 'when alerts service is active' do
let!(:alerts_service) { create(:alerts_service, project: project) }
it 'updates issue title with the IID' do
issue.save
it 'updates issue title with the IID' do
issue.save
expect(issue.reload.title).to eq("New: Incident #{issue.id}")
end
end
context 'when alerts service is not active' do
it 'does not change issue title' do
expect { issue.save }.not_to change { issue.title }
end
expect(issue.reload.title).to eq("New: Incident #{issue.id}")
end
end
context 'when incident management is not available' do
context 'when alerts service is not active' do
before do
stub_licensed_features(incident_management: false)
allow(project).to receive(:alerts_service_activated?).and_return(false)
end
it 'does not change issue title' do
......
......@@ -5329,6 +5329,42 @@ describe Project do
end
end
describe '#alerts_service_activated?' do
let!(:project) { create(:project) }
subject { project.alerts_service_activated? }
context 'when incident management feature available' do
before do
stub_licensed_features(incident_management: true)
end
context 'when project has an activated alerts service' do
before do
create(:alerts_service, project: project)
end
it { is_expected.to be_truthy }
end
context 'when project has an inactive alerts service' do
before do
create(:alerts_service, :inactive, project: project)
end
it { is_expected.to be_falsey }
end
end
context 'when incident feature is not available' do
before do
stub_licensed_features(incident_management: false)
end
it { is_expected.to be_falsey }
end
end
def rugged_config
rugged_repo(project.repository).config
end
......
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