Commit c82d8413 authored by Sean Arnold's avatar Sean Arnold

Tweak some spec syntax

- Remove old file
parent 2d77fed6
......@@ -5,16 +5,15 @@ module IncidentManagement
include ApplicationWorker
include CronjobQueue # rubocop:disable Scalability/CronWorkerContext
idempotent!
feature_category :incident_management
def perform
IncidentSla.exceeded.find_in_batches do |incident_slas|
IssuableSla.exceeded_for_issues.find_in_batches do |incident_slas|
incident_slas.each do |incident_sla|
ApplyIncidentSlaExceededLabelService.new(incident_sla.issue).execute
rescue StandardError => e
rescue StandardError => e
Gitlab::AppLogger.error("Error encountered in #{self.class.name}: #{e}")
end
end
......
......@@ -16,19 +16,22 @@ RSpec.describe IssuableSla do
subject { described_class.exceeded_for_issues }
let_it_be(:project) { create(:project) }
let!(:issuable_sla) { create(:issuable_sla, issue: issue, due_at: due_at) }
let(:due_at) { Time.current - 1.hour }
let(:issue) { create(:issue, project: project) }
let_it_be_with_reload(:issue) { create(:issue, project: project) }
let_it_be_with_reload(:issuable_sla) { create(:issuable_sla, issue: issue, due_at: Time.current - 1.hour) }
context 'issue closed' do
let(:issue) { create(:issue, :closed, project: project) }
before do
issue.close!
end
it { is_expected.to be_empty }
end
context 'issue opened' do
context 'due_at has not passed' do
let(:due_at) { Time.current + 1.hour }
before do
issuable_sla.update!(due_at: Time.current + 1.hour)
end
it { is_expected.to be_empty }
end
......
......@@ -12,7 +12,7 @@ RSpec.describe IncidentManagement::ApplyIncidentSlaExceededLabelService do
.payload[:label]
end
subject { described_class.new(incident).execute }
subject(:apply_label) { described_class.new(incident).execute }
context 'label exists already' do
before do
......@@ -25,7 +25,11 @@ RSpec.describe IncidentManagement::ApplyIncidentSlaExceededLabelService do
end
it 'adds a label to the incident' do
expect { subject }.to change { incident.labels.reload.count }
expect { apply_label }.to change { incident.labels.reload.count }.by(1)
expected_props = IncidentManagement::CreateIncidentSlaExceededLabelService::LABEL_PROPERTIES
expect(apply_label).to have_attributes(expected_props)
end
it 'adds a note that the label was added' do
......
......@@ -8,9 +8,8 @@ RSpec.describe IncidentManagement::IncidentSlaExceededCheckWorker do
describe '#perform' do
subject(:perform) { worker.perform }
let_it_be(:incident_1) { create(:incident_sla, :exceeded) }
let_it_be(:incident_2) { create(:incident_sla, :exceeded) }
let_it_be(:incident_3) { create(:incident_sla, :exceeded) }
let_it_be(:incident_sla) { create(:issuable_sla, :exceeded) }
let_it_be(:other_incident_slas) { create_list(:issuable_sla, 2, :exceeded) }
let(:label_service_stub) { instance_double(IncidentManagement::ApplyIncidentSlaExceededLabelService, execute: true) }
......@@ -33,13 +32,13 @@ RSpec.describe IncidentManagement::IncidentSlaExceededCheckWorker do
allow(IncidentManagement::ApplyIncidentSlaExceededLabelService)
.to receive(:new)
.with(incident_1.issue)
.with(incident_sla.issue)
.and_raise('test')
end
it 'logs the error and continues to run the others' do
expect(Gitlab::AppLogger).to receive(:error).once
expect(label_service_stub).to receive(:execute).exactly(2).times
expect(label_service_stub).to receive(:execute).twice
perform
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