diff options
author | Thong Kuah <tkuah@gitlab.com> | 2019-07-01 20:27:58 +1200 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2019-07-08 09:13:21 +1200 |
commit | 1b5b0dea5228ae7fd520c8bca3f03c4799a4d31d (patch) | |
tree | 0969a78c3b959cf33b47a0de308fa385c62af157 /spec | |
parent | 1668f40f430c656ed9c20898605db21a66cb5937 (diff) | |
download | gitlab-ce-1b5b0dea5228ae7fd520c8bca3f03c4799a4d31d.tar.gz |
Share project object in EnvironmentStatus
Otherwise, each EnvironmentStatus object instantiates its own project
when really they are the same. Improves query count performance
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/environment_status_spec.rb | 3 | ||||
-rw-r--r-- | spec/serializers/environment_status_entity_spec.rb | 10 |
2 files changed, 9 insertions, 4 deletions
diff --git a/spec/models/environment_status_spec.rb b/spec/models/environment_status_spec.rb index c503c35305f..e2836420df9 100644 --- a/spec/models/environment_status_spec.rb +++ b/spec/models/environment_status_spec.rb @@ -11,11 +11,10 @@ describe EnvironmentStatus do let(:merge_request) { create(:merge_request, :deployed_review_app, deployment: deployment) } let(:sha) { deployment.sha } - subject(:environment_status) { described_class.new(environment, merge_request, sha) } + subject(:environment_status) { described_class.new(project, environment, merge_request, sha) } it { is_expected.to delegate_method(:id).to(:environment) } it { is_expected.to delegate_method(:name).to(:environment) } - it { is_expected.to delegate_method(:project).to(:environment) } it { is_expected.to delegate_method(:deployed_at).to(:deployment) } it { is_expected.to delegate_method(:status).to(:deployment) } diff --git a/spec/serializers/environment_status_entity_spec.rb b/spec/serializers/environment_status_entity_spec.rb index 8a6a38fe5f8..f421432e8d6 100644 --- a/spec/serializers/environment_status_entity_spec.rb +++ b/spec/serializers/environment_status_entity_spec.rb @@ -9,7 +9,7 @@ describe EnvironmentStatusEntity do let(:project) { deployment.project } let(:merge_request) { create(:merge_request, :deployed_review_app, deployment: deployment) } - let(:environment_status) { EnvironmentStatus.new(environment, merge_request, merge_request.diff_head_sha) } + let(:environment_status) { EnvironmentStatus.new(project, environment, merge_request, merge_request.diff_head_sha) } let(:entity) { described_class.new(environment_status, request: request) } subject { entity.as_json } @@ -55,8 +55,14 @@ describe EnvironmentStatusEntity do before do project.add_maintainer(user) allow(deployment).to receive(:prometheus_adapter).and_return(prometheus_adapter) - allow(prometheus_adapter).to receive(:query).with(:deployment, deployment).and_return(simple_metrics) allow(entity).to receive(:deployment).and_return(deployment) + + expect_next_instance_of(DeploymentMetrics) do |deployment_metrics| + allow(deployment_metrics).to receive(:prometheus_adapter).and_return(prometheus_adapter) + + allow(prometheus_adapter).to receive(:query) + .with(:deployment, deployment).and_return(simple_metrics) + end end context 'when deployment succeeded' do |