Commit 99e12104 authored by Sean Arnold's avatar Sean Arnold

Add exceeded scope to Incident SLA

parent 4d8b02a4
...@@ -3,4 +3,6 @@ ...@@ -3,4 +3,6 @@
class IssuableSla < ApplicationRecord 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, -> { joins(:issue).merge(Issue.opened).where('due_at < ?', Time.current) }
end end
...@@ -10,4 +10,31 @@ RSpec.describe IssuableSla do ...@@ -10,4 +10,31 @@ RSpec.describe IssuableSla do
describe 'validations' do describe 'validations' do
it { is_expected.to validate_presence_of(:due_at) } it { is_expected.to validate_presence_of(:due_at) }
end end
describe 'scopes' do
describe '.exceeded_for_issues' 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) }
context 'issue closed' do
let(:issue) { create(:issue, :closed, project: project) }
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 }
it { is_expected.to be_empty }
end
it { is_expected.to contain_exactly(issuable_sla) }
end
end
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