Commit ca6aa800 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'sy-track-publishing' into 'master'

Add support for tracking when an issue is published/unpublished

See merge request gitlab-org/gitlab!30893
parents 3eddd876 a168ed0e
# frozen_string_literal: true
module StatusPage
# Corresponds to an issue which has been published to a
# status-page app's AWS bucket.
# Corresponds to an issue which has been published to the Status Page.
class PublishedIncident < ApplicationRecord
self.table_name = "status_page_published_incidents"
belongs_to :issue, inverse_of: :status_page_published_incident
validates :issue, presence: true
def self.track(issue)
safe_find_or_create_by(issue: issue)
end
def self.untrack(issue)
find_by(issue: issue)&.destroy
end
end
end
......@@ -10,4 +10,42 @@ describe StatusPage::PublishedIncident do
describe 'validation' do
it { is_expected.to validate_presence_of(:issue) }
end
describe '.track' do
let_it_be(:issue) { create(:issue) }
subject { described_class.track(issue) }
it { is_expected.to be_a(described_class) }
specify { expect(subject.issue).to eq issue }
specify { expect { subject }.to change { described_class.count }.by(1) }
context 'when the incident already exists' do
before do
create(:status_page_published_incident, issue: issue)
end
it { is_expected.to be_a(described_class) }
specify { expect(subject.issue).to eq issue }
specify { expect { subject }.not_to change { described_class.count } }
end
end
describe '.untrack' do
let_it_be(:issue) { create(:issue) }
subject { described_class.untrack(issue) }
context 'when the incident is not yet tracked' do
specify { expect { subject }.not_to change { described_class.count } }
end
context 'when the incident is already tracked' do
before do
create(:status_page_published_incident, issue: issue)
end
specify { expect { subject }.to change { described_class.count }.by(-1) }
end
end
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