Commit 010461d9 authored by Brett Walker's avatar Brett Walker

Added spec to check for disabled services

parent 87000ab7
......@@ -4353,18 +4353,39 @@ describe Project do
end
end
describe "#find_or_initialize_service" do
subject { build(:project) }
end
it 'avoids N+1 database queries' do
allow(Service).to receive(:available_services_names).and_return(%w(prometheus pushover))
describe "#find_or_initialize_services" do
subject { build(:project) }
control_count = ActiveRecord::QueryRecorder.new { project.find_or_initialize_service('prometheus') }.count
it 'returns only enabled services' do
allow(Service).to receive(:available_services_names).and_return(%w(prometheus pushover))
allow(subject).to receive(:disabled_services).and_return(%w(prometheus))
allow(Service).to receive(:available_services_names).and_call_original
services = subject.find_or_initialize_services
expect { project.find_or_initialize_service('prometheus') }.not_to exceed_query_limit(control_count)
end
expect(services.count).to eq 1
expect(services).to include(PushoverService)
end
end
describe "#find_or_initialize_service" do
subject { build(:project) }
it 'avoids N+1 database queries' do
allow(Service).to receive(:available_services_names).and_return(%w(prometheus pushover))
control_count = ActiveRecord::QueryRecorder.new { subject.find_or_initialize_service('prometheus') }.count
allow(Service).to receive(:available_services_names).and_call_original
expect { subject.find_or_initialize_service('prometheus') }.not_to exceed_query_limit(control_count)
end
it 'returns nil if service is disabled' do
allow(subject).to receive(:disabled_services).and_return(%w(prometheus))
expect(subject.find_or_initialize_service('prometheus')).to be_nil
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