Commit d6528bb4 authored by Sean Arnold's avatar Sean Arnold

Refactor specs to reduce complexity

parent f3697d79
...@@ -224,32 +224,43 @@ describe AlertManagement::AlertsFinder, '#execute' do ...@@ -224,32 +224,43 @@ describe AlertManagement::AlertsFinder, '#execute' do
end end
context 'search query given' do context 'search query given' do
let_it_be(:alert) do
create(:alert_management_alert,
:with_fingerprint,
project: project,
title: 'Title',
description: 'Desc',
service: 'Service',
monitoring_tool: 'Monitor'
)
end
context 'searching title' do context 'searching title' do
let(:params) { { search: alert_1.title } } let(:params) { { search: alert.title } }
it { is_expected.to match_array([alert_1]) } it { is_expected.to match_array([alert]) }
end end
context 'searching description' do context 'searching description' do
let(:params) { { search: alert_1.description } } let(:params) { { search: alert.description } }
it { is_expected.to match_array([alert_1]) } it { is_expected.to match_array([alert]) }
end end
context 'searching service' do context 'searching service' do
let(:params) { { search: alert_1.service } } let(:params) { { search: alert.service } }
it { is_expected.to match_array([alert_1]) } it { is_expected.to match_array([alert]) }
end end
context 'searching monitoring tool' do context 'searching monitoring tool' do
let(:params) { { search: alert_1.monitoring_tool } } let(:params) { { search: alert.monitoring_tool } }
it { is_expected.to match_array([alert_1]) } it { is_expected.to match_array([alert]) }
end end
context 'searching something else' do context 'searching something else' do
let(:params) { { search: alert_1.fingerprint } } let(:params) { { search: alert.fingerprint } }
it { is_expected.to be_empty } it { is_expected.to be_empty }
end end
......
...@@ -163,37 +163,43 @@ describe AlertManagement::Alert do ...@@ -163,37 +163,43 @@ describe AlertManagement::Alert do
end end
describe '.search' do describe '.search' do
let(:query) { 'rspec' } let_it_be(:alert) do
let(:attribute_data) { 'RSPEC data' } create(:alert_management_alert,
title: 'Title',
description: 'Desc',
service: 'Service',
monitoring_tool: 'Monitor'
)
end
subject { AlertManagement::Alert.search(query) } subject { AlertManagement::Alert.search(query) }
context 'does not contain search string' do context 'does not contain search string' do
let!(:alert) { create(:alert_management_alert) } let(:query) { 'something else' }
it { is_expected.to be_empty } it { is_expected.to be_empty }
end end
context 'title includes query' do context 'title includes query' do
let!(:alert) { create(:alert_management_alert, title: attribute_data) } let(:query) { alert.title.upcase }
it { is_expected.to contain_exactly(alert) } it { is_expected.to contain_exactly(alert) }
end end
context 'description includes query' do context 'description includes query' do
let!(:alert) { create(:alert_management_alert, description: attribute_data) } let(:query) { alert.description.upcase }
it { is_expected.to contain_exactly(alert) } it { is_expected.to contain_exactly(alert) }
end end
context 'service includes query' do context 'service includes query' do
let!(:alert) { create(:alert_management_alert, service: attribute_data) } let(:query) { alert.service.upcase }
it { is_expected.to contain_exactly(alert) } it { is_expected.to contain_exactly(alert) }
end end
context 'monitoring tool includes query' do context 'monitoring tool includes query' do
let!(:alert) { create(:alert_management_alert, monitoring_tool: attribute_data) } let(:query) { alert.monitoring_tool.upcase }
it { is_expected.to contain_exactly(alert) } it { is_expected.to contain_exactly(alert) }
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