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