diff options
author | Douwe Maan <douwe@gitlab.com> | 2019-04-29 10:25:32 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2019-04-29 10:25:32 +0000 |
commit | bead65a9d324542cde464ecc6da2393c30f67769 (patch) | |
tree | 3f8dab112c87e54ae591425a2f739aa6f7410660 | |
parent | ab9910f7a5fe4981b330c3886865397fd066108d (diff) | |
parent | 80fec5c3295977c5559c420f51fd774391d3ca91 (diff) | |
download | gitlab-ce-bead65a9d324542cde464ecc6da2393c30f67769.tar.gz |
Merge branch 'pl-env-metrics-json' into 'master'
Load environment metrics only for JSON endpoint
See merge request gitlab-org/gitlab-ce!27743
-rw-r--r-- | app/controllers/projects/environments_controller.rb | 8 | ||||
-rw-r--r-- | spec/controllers/projects/environments_controller_spec.rb | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index 1f619c8fd2f..4aa572ade73 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -135,13 +135,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController end def metrics - # Currently, this acts as a hint to load the metrics details into the cache - # if they aren't there already - @metrics = environment.metrics || {} - respond_to do |format| format.html format.json do + # Currently, this acts as a hint to load the metrics details into the cache + # if they aren't there already + @metrics = environment.metrics || {} + render json: @metrics, status: @metrics.any? ? :ok : :no_content end end diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb index c1c4be45168..a62422d0229 100644 --- a/spec/controllers/projects/environments_controller_spec.rb +++ b/spec/controllers/projects/environments_controller_spec.rb @@ -342,11 +342,9 @@ describe Projects::EnvironmentsController do end context 'when environment has no metrics' do - before do - expect(environment).to receive(:metrics).and_return(nil) - end - it 'returns a metrics page' do + expect(environment).not_to receive(:metrics) + get :metrics, params: environment_params expect(response).to be_ok @@ -354,6 +352,8 @@ describe Projects::EnvironmentsController do context 'when requesting metrics as JSON' do it 'returns a metrics JSON document' do + expect(environment).to receive(:metrics).and_return(nil) + get :metrics, params: environment_params(format: :json) expect(response).to have_gitlab_http_status(204) |