Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-10-06 23:55:01 +0300
committerStan Hu <stanhu@gmail.com>2018-10-06 23:55:01 +0300
commitc3389c8006443e2b4d994eb15e60bd249fc4732f (patch)
treecd9907005e22cee90cd646d0d994783c93fceb4c /spec
parent2fce6d6f9b28bb8136c23ec89c0efe143694dbc4 (diff)
parentf934b2160384a177d01f66b606d57961a1c8a3cb (diff)
Merge branch 'bw-fix-checking-disabled-services' into 'master'51761-create-new-project-auto-populate-project-slug-string-to-project-name-if-name-is-empty
Check disabled_services when finding a service See merge request gitlab-org/gitlab-ce!22172
Diffstat (limited to 'spec')
-rw-r--r--spec/models/project_spec.rb36
1 files changed, 28 insertions, 8 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index ff259dc12b3..31c69e5bd2c 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -4037,19 +4037,39 @@ describe Project do
expect(result).to be_empty
end
end
+ end
- describe "#find_or_initialize_service" do
- subject { build(:project) }
+ describe "#find_or_initialize_services" do
+ subject { build(:project) }
- it 'avoids N+1 database queries' do
- allow(Service).to receive(:available_services_names).and_return(%w(prometheus pushover))
+ 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))
- control_count = ActiveRecord::QueryRecorder.new { project.find_or_initialize_service('prometheus') }.count
+ services = subject.find_or_initialize_services
- allow(Service).to receive(:available_services_names).and_call_original
+ expect(services.count).to eq 1
+ expect(services).to include(PushoverService)
+ end
+ end
- expect { project.find_or_initialize_service('prometheus') }.not_to exceed_query_limit(control_count)
- 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