summaryrefslogtreecommitdiff
path: root/spec/controllers/projects/environments_controller_spec.rb
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-06-05 18:38:09 +0200
committerPawel Chojnacki <pawel@chojnacki.ws>2017-06-05 18:38:09 +0200
commit223d07b38315a68fe39df90a7675f043d8b7acaf (patch)
tree35958a1deac9ac0148e54d0737417199e771c841 /spec/controllers/projects/environments_controller_spec.rb
parentcf4aeafa6f3baaec7652f486cd04b7170dde9fbf (diff)
downloadgitlab-ce-223d07b38315a68fe39df90a7675f043d8b7acaf.tar.gz
Environments#additional_metrics tests
Diffstat (limited to 'spec/controllers/projects/environments_controller_spec.rb')
-rw-r--r--spec/controllers/projects/environments_controller_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb
index 20f99b209eb..12efdc700c5 100644
--- a/spec/controllers/projects/environments_controller_spec.rb
+++ b/spec/controllers/projects/environments_controller_spec.rb
@@ -311,6 +311,46 @@ describe Projects::EnvironmentsController do
end
end
+ describe 'GET #additional_metrics' do
+ before do
+ allow(controller).to receive(:environment).and_return(environment)
+ end
+
+ context 'when environment has no metrics' do
+ before do
+ expect(environment).to receive(:additional_metrics).and_return(nil)
+ end
+
+ context 'when requesting metrics as JSON' do
+ it 'returns a metrics JSON document' do
+ get :additional_metrics, environment_params(format: :json)
+
+ expect(response).to have_http_status(204)
+ expect(json_response).to eq({})
+ end
+ end
+ end
+
+ context 'when environment has some metrics' do
+ before do
+ expect(environment).to receive(:additional_metrics).and_return({
+ success: true,
+ data: {},
+ last_update: 42
+ })
+ end
+
+ it 'returns a metrics JSON document' do
+ get :additional_metrics, environment_params(format: :json)
+
+ expect(response).to be_ok
+ expect(json_response['success']).to be(true)
+ expect(json_response['data']).to eq({})
+ expect(json_response['last_update']).to eq(42)
+ end
+ end
+ end
+
def environment_params(opts = {})
opts.reverse_merge(namespace_id: project.namespace,
project_id: project,