diff options
author | Sarah Yasonik <syasonik@gitlab.com> | 2019-07-29 23:03:59 +0000 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2019-07-29 23:03:59 +0000 |
commit | dfe13131d705c739a3b8747e70c004aaf2e58856 (patch) | |
tree | cbaf47bcedf0d518af7c6bf5cafbb59dbade78d7 /spec/services/metrics/dashboard/system_dashboard_service_spec.rb | |
parent | 95838fe44dfc5aa48428b09b4288ac1e1d637f94 (diff) | |
download | gitlab-ce-dfe13131d705c739a3b8747e70c004aaf2e58856.tar.gz |
Move BaseService to Services directory
In preparation for embedding specific metrics in issues
https://gitlab.com/gitlab-org/gitlab-ce/issues/62971,
this commit moves the BaseService for metrics dashboards
to a new services subdirectory. This is purely for the sake
of organization and maintainability.
Diffstat (limited to 'spec/services/metrics/dashboard/system_dashboard_service_spec.rb')
-rw-r--r-- | spec/services/metrics/dashboard/system_dashboard_service_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/services/metrics/dashboard/system_dashboard_service_spec.rb b/spec/services/metrics/dashboard/system_dashboard_service_spec.rb new file mode 100644 index 00000000000..8be3e7f6064 --- /dev/null +++ b/spec/services/metrics/dashboard/system_dashboard_service_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Metrics::Dashboard::SystemDashboardService, :use_clean_rails_memory_store_caching do + include MetricsDashboardHelpers + + set(:user) { create(:user) } + set(:project) { create(:project) } + set(:environment) { create(:environment, project: project) } + + before do + project.add_maintainer(user) + end + + describe 'get_dashboard' do + let(:dashboard_path) { described_class::SYSTEM_DASHBOARD_PATH } + let(:service_params) { [project, user, { environment: environment, dashboard_path: dashboard_path }] } + let(:service_call) { described_class.new(*service_params).get_dashboard } + + it_behaves_like 'valid dashboard service response' + it_behaves_like 'raises error for users with insufficient permissions' + + it 'caches the unprocessed dashboard for subsequent calls' do + expect(YAML).to receive(:safe_load).once.and_call_original + + described_class.new(*service_params).get_dashboard + described_class.new(*service_params).get_dashboard + end + + context 'when called with a non-system dashboard' do + let(:dashboard_path) { 'garbage/dashboard/path' } + + # We want to alwaus return the system dashboard. + it_behaves_like 'valid dashboard service response' + end + end + + describe '::all_dashboard_paths' do + it 'returns the dashboard attributes' do + all_dashboards = described_class.all_dashboard_paths(project) + + expect(all_dashboards).to eq( + [{ + path: described_class::SYSTEM_DASHBOARD_PATH, + display_name: described_class::SYSTEM_DASHBOARD_NAME, + default: true + }] + ) + end + end +end |