Commit f983eb8c authored by Sean Arnold's avatar Sean Arnold

Fix issuable sla scope

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