Commit 00f87838 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Add :with_validation_errors trait for Alert

parent 339c39b3
...@@ -8,6 +8,13 @@ FactoryBot.define do ...@@ -8,6 +8,13 @@ FactoryBot.define do
title { FFaker::Lorem.sentence } title { FFaker::Lorem.sentence }
started_at { Time.current } started_at { Time.current }
trait :with_validation_errors do
after(:create) do |alert|
too_many_hosts = Array.new(AlertManagement::Alert::HOSTS_MAX_LENGTH + 1) { |_| 'host' }
alert.update_columns(hosts: too_many_hosts)
end
end
trait :with_issue do trait :with_issue do
issue issue
end end
......
...@@ -94,11 +94,7 @@ RSpec.describe AlertManagement::CreateAlertIssueService do ...@@ -94,11 +94,7 @@ RSpec.describe AlertManagement::CreateAlertIssueService do
end end
context 'when alert cannot be updated' do context 'when alert cannot be updated' do
before do let(:alert) { create(:alert_management_alert, :with_validation_errors, :triggered, project: project, payload: payload) }
# invalidate alert
too_many_hosts = Array.new(AlertManagement::Alert::HOSTS_MAX_LENGTH + 1) { |_| 'host' }
alert.update_columns(hosts: too_many_hosts)
end
it 'responds with error' do it 'responds with error' do
expect(execute).to be_error expect(execute).to be_error
......
...@@ -70,11 +70,7 @@ describe IncidentManagement::ProcessAlertWorker do ...@@ -70,11 +70,7 @@ describe IncidentManagement::ProcessAlertWorker do
end end
context 'when alert cannot be updated' do context 'when alert cannot be updated' do
before do let(:alert) { create(:alert_management_alert, :with_validation_errors, project: project) }
# invalidate alert
too_many_hosts = Array.new(AlertManagement::Alert::HOSTS_MAX_LENGTH + 1) { |_| 'host' }
alert.update_columns(hosts: too_many_hosts)
end
it 'updates AlertManagement::Alert#issue_id' do it 'updates AlertManagement::Alert#issue_id' do
expect { subject }.not_to change { alert.reload.issue_id } expect { subject }.not_to change { alert.reload.issue_id }
......
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