Commit f983eb8c authored by Sean Arnold's avatar Sean Arnold

Fix issuable sla scope

Fix worker spec
parent e2c3cc8f
......@@ -142,6 +142,8 @@
- 2
- - incident_management
- 2
- - incident_management_apply_incident_sla_exceeded_label
- 1
- - invalid_gpg_signature_update
- 2
- - irker
......
......@@ -4,5 +4,5 @@ class IssuableSla < ApplicationRecord
belongs_to :issue, optional: false
validates :due_at, presence: true
scope :exceeded_for_issues, -> { includes(:issue).merge(Issue.opened).where('due_at < ?', Time.current) }
scope :exceeded_for_issues, -> { includes(:issue).joins(:issue).merge(Issue.opened).where('due_at < ?', Time.current) }
end
......@@ -8,7 +8,7 @@ module IncidentManagement
feature_category :incident_management
def perform(incident_id)
@incident = Issue.find_by(id: incident_id)
@incident = Issue.find_by_id(incident_id)
@project = incident&.project
return unless incident && project
......
......@@ -2,6 +2,6 @@
require 'spec_helper'
RSpec.describe IncidentManagement::CreateIncidentLabelService do
RSpec.describe IncidentManagement::CreateIncidentSlaExceededLabelService do
it_behaves_like 'incident management label service'
end
......@@ -11,34 +11,32 @@ RSpec.describe IncidentManagement::IncidentSlaExceededCheckWorker do
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) }
let(:label_service_stub) { instance_double(IncidentManagement::ApplyIncidentSlaExceededLabelWorker) }
it 'calls the apply incident sla label service' do
expect(IncidentManagement::ApplyIncidentSlaExceededLabelService)
.to receive(:new)
expect(IncidentManagement::ApplyIncidentSlaExceededLabelWorker)
.to receive(:perform_async)
.exactly(3)
.and_return(label_service_stub)
expect(label_service_stub).to receive(:execute).exactly(3).times
.times
perform
end
context 'when error occurs' do
before do
allow(IncidentManagement::ApplyIncidentSlaExceededLabelService)
.to receive(:new)
.and_return(label_service_stub)
allow(IncidentManagement::ApplyIncidentSlaExceededLabelWorker)
.to receive(:perform_async)
.twice
allow(IncidentManagement::ApplyIncidentSlaExceededLabelService)
.to receive(:new)
.with(incident_sla.issue)
allow(IncidentManagement::ApplyIncidentSlaExceededLabelWorker)
.to receive(:perform_async)
.with(incident_sla.issue.id)
.and_raise('test')
.once
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).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