diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2018-08-01 18:17:47 +0300 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2018-08-01 18:17:47 +0300 |
commit | ea6fc714bb0306ac8ca56b5dafe4b6777aafe5fc (patch) | |
tree | 5d9673f0e526acbdb3285147024064f89d45dc23 /spec | |
parent | 47244ad5ea4e887ecb6dffa9f7b96846adbf4b6f (diff) | |
parent | 29dd1c14db6899c3858ca906e076c7b7fbbaa0e2 (diff) |
Merge branch '41416-making-instance-wide-data-tools-more-accessible' into 'master'
Resolve "Making instance-wide data tools more accessible"
Closes #41416 and #48507
See merge request gitlab-org/gitlab-ce!20874
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/instance_statistics/cohorts_controller_spec.rb | 7 | ||||
-rw-r--r-- | spec/controllers/instance_statistics/conversational_development_index_controller_spec.rb | 7 | ||||
-rw-r--r-- | spec/features/dashboard/active_tab_spec.rb | 28 | ||||
-rw-r--r-- | spec/features/dashboard/instance_statistics_spec.rb | 60 | ||||
-rw-r--r-- | spec/features/instance_statistics/cohorts_spec.rb (renamed from spec/features/admin/admin_cohorts_spec.rb) | 4 | ||||
-rw-r--r-- | spec/features/instance_statistics/conversational_development_index_spec.rb (renamed from spec/features/admin/admin_conversational_development_index_spec.rb) | 8 | ||||
-rw-r--r-- | spec/policies/global_policy_spec.rb | 34 | ||||
-rw-r--r-- | spec/requests/api/settings_spec.rb | 5 | ||||
-rw-r--r-- | spec/routing/instance_statistics_routing_spec.rb | 11 | ||||
-rw-r--r-- | spec/support/shared_examples/instance_statistics_controllers_shared_examples.rb | 37 |
10 files changed, 183 insertions, 18 deletions
diff --git a/spec/controllers/instance_statistics/cohorts_controller_spec.rb b/spec/controllers/instance_statistics/cohorts_controller_spec.rb new file mode 100644 index 00000000000..e4eedede93a --- /dev/null +++ b/spec/controllers/instance_statistics/cohorts_controller_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe InstanceStatistics::CohortsController do + it_behaves_like 'instance statistics availability' +end diff --git a/spec/controllers/instance_statistics/conversational_development_index_controller_spec.rb b/spec/controllers/instance_statistics/conversational_development_index_controller_spec.rb new file mode 100644 index 00000000000..4935cb265bf --- /dev/null +++ b/spec/controllers/instance_statistics/conversational_development_index_controller_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe InstanceStatistics::ConversationalDevelopmentIndexController do + it_behaves_like 'instance statistics availability' +end diff --git a/spec/features/dashboard/active_tab_spec.rb b/spec/features/dashboard/active_tab_spec.rb index 8bab501134b..f4d0f82d248 100644 --- a/spec/features/dashboard/active_tab_spec.rb +++ b/spec/features/dashboard/active_tab_spec.rb @@ -7,32 +7,38 @@ RSpec.describe 'Dashboard Active Tab', :js do shared_examples 'page has active tab' do |title| it "#{title} tab" do + subject + expect(page).to have_selector('.navbar-sub-nav li.active', count: 1) expect(find('.navbar-sub-nav li.active')).to have_content(title) end end context 'on dashboard projects' do - before do - visit dashboard_projects_path + it_behaves_like 'page has active tab', 'Projects' do + subject { visit dashboard_projects_path } end - - it_behaves_like 'page has active tab', 'Projects' end context 'on dashboard groups' do - before do - visit dashboard_groups_path + it_behaves_like 'page has active tab', 'Groups' do + subject { visit dashboard_groups_path } end - - it_behaves_like 'page has active tab', 'Groups' end context 'on activity projects' do - before do - visit activity_dashboard_path + it_behaves_like 'page has active tab', 'Activity' do + subject { visit activity_dashboard_path } end + end - it_behaves_like 'page has active tab', 'Activity' + context 'on instance statistics' do + subject { visit instance_statistics_root_path } + + it 'shows Instance Statistics` as active' do + subject + + expect(find('.navbar-sub-nav li.active')).to have_link('Instance Statistics') + end end end diff --git a/spec/features/dashboard/instance_statistics_spec.rb b/spec/features/dashboard/instance_statistics_spec.rb new file mode 100644 index 00000000000..21ee2796bd8 --- /dev/null +++ b/spec/features/dashboard/instance_statistics_spec.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Showing instance statistics' do + before do + sign_in user if user + end + + # Using a path that is publicly accessible + subject { visit explore_projects_path } + + context 'for unauthenticated users' do + let(:user) { nil } + + it 'does not show the instance statistics link' do + subject + + expect(page).not_to have_link('Instance Statistics') + end + end + + context 'for regular users' do + let(:user) { create(:user) } + + context 'when instance statistics are publicly available' do + before do + stub_application_setting(instance_statistics_visibility_private: false) + end + + it 'shows the instance statistics link' do + subject + + expect(page).to have_link('Instance Statistics') + end + end + + context 'when instance statistics are not publicly available' do + before do + stub_application_setting(instance_statistics_visibility_private: true) + end + + it 'shows the instance statistics link' do + subject + + expect(page).not_to have_link('Instance Statistics') + end + end + end + + context 'for admins' do + let(:user) { create(:admin) } + + it 'shows the instance statistics link' do + subject + + expect(page).to have_link('Instance Statistics') + end + end +end diff --git a/spec/features/admin/admin_cohorts_spec.rb b/spec/features/instance_statistics/cohorts_spec.rb index 9dce9494b97..81fc5eff980 100644 --- a/spec/features/admin/admin_cohorts_spec.rb +++ b/spec/features/instance_statistics/cohorts_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe 'Admin cohorts page' do +describe 'Cohorts page' do before do sign_in(create(:admin)) end @@ -8,7 +8,7 @@ describe 'Admin cohorts page' do it 'See users count per month' do 2.times { create(:user) } - visit admin_cohorts_path + visit instance_statistics_cohorts_path expect(page).to have_content("#{Time.now.strftime('%b %Y')} 3 0") end diff --git a/spec/features/admin/admin_conversational_development_index_spec.rb b/spec/features/instance_statistics/conversational_development_index_spec.rb index 2d2c7df5364..d441a7a5af9 100644 --- a/spec/features/admin/admin_conversational_development_index_spec.rb +++ b/spec/features/instance_statistics/conversational_development_index_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'Admin Conversational Development Index' do +describe 'Conversational Development Index' do before do sign_in(create(:admin)) end @@ -9,7 +9,7 @@ describe 'Admin Conversational Development Index' do it 'shows empty state' do stub_application_setting(usage_ping_enabled: false) - visit admin_conversational_development_index_path + visit instance_statistics_conversational_development_index_index_path expect(page).to have_content('Usage ping is not enabled') end @@ -19,7 +19,7 @@ describe 'Admin Conversational Development Index' do it 'shows empty state' do stub_application_setting(usage_ping_enabled: true) - visit admin_conversational_development_index_path + visit instance_statistics_conversational_development_index_index_path expect(page).to have_content('Data is still calculating') end @@ -30,7 +30,7 @@ describe 'Admin Conversational Development Index' do stub_application_setting(usage_ping_enabled: true) create(:conversational_development_index_metric) - visit admin_conversational_development_index_path + visit instance_statistics_conversational_development_index_index_path expect(page).to have_content( 'Issues created per active user 1.2 You 9.3 Lead 13.3%' diff --git a/spec/policies/global_policy_spec.rb b/spec/policies/global_policy_spec.rb index a2047b54deb..30d68e7dc9d 100644 --- a/spec/policies/global_policy_spec.rb +++ b/spec/policies/global_policy_spec.rb @@ -180,4 +180,38 @@ describe GlobalPolicy do end end end + + describe 'read instance statistics' do + context 'regular user' do + it { is_expected.to be_allowed(:read_instance_statistics) } + + context 'when instance statistics are set to private' do + before do + stub_application_setting(instance_statistics_visibility_private: true) + end + + it { is_expected.not_to be_allowed(:read_instance_statistics) } + end + end + + context 'admin' do + let(:current_user) { create(:admin) } + + it { is_expected.to be_allowed(:read_instance_statistics) } + + context 'when instance statistics are set to private' do + before do + stub_application_setting(instance_statistics_visibility_private: true) + end + + it { is_expected.to be_allowed(:read_instance_statistics) } + end + end + + context 'anonymous' do + let(:current_user) { nil } + + it { is_expected.not_to be_allowed(:read_instance_statistics) } + end + end end diff --git a/spec/requests/api/settings_spec.rb b/spec/requests/api/settings_spec.rb index 57adc3ca7a6..3e0f47b84a1 100644 --- a/spec/requests/api/settings_spec.rb +++ b/spec/requests/api/settings_spec.rb @@ -25,6 +25,7 @@ describe API::Settings, 'Settings' do expect(json_response['ed25519_key_restriction']).to eq(0) expect(json_response['circuitbreaker_failure_count_threshold']).not_to be_nil expect(json_response['performance_bar_allowed_group_id']).to be_nil + expect(json_response['instance_statistics_visibility_private']).to be(false) expect(json_response).not_to have_key('performance_bar_allowed_group_path') expect(json_response).not_to have_key('performance_bar_enabled') end @@ -64,7 +65,8 @@ describe API::Settings, 'Settings' do circuitbreaker_check_interval: 2, enforce_terms: true, terms: 'Hello world!', - performance_bar_allowed_group_path: group.full_path + performance_bar_allowed_group_path: group.full_path, + instance_statistics_visibility_private: true expect(response).to have_gitlab_http_status(200) expect(json_response['default_projects_limit']).to eq(3) @@ -89,6 +91,7 @@ describe API::Settings, 'Settings' do expect(json_response['enforce_terms']).to be(true) expect(json_response['terms']).to eq('Hello world!') expect(json_response['performance_bar_allowed_group_id']).to eq(group.id) + expect(json_response['instance_statistics_visibility_private']).to be(true) end end diff --git a/spec/routing/instance_statistics_routing_spec.rb b/spec/routing/instance_statistics_routing_spec.rb new file mode 100644 index 00000000000..b94faabfa1d --- /dev/null +++ b/spec/routing/instance_statistics_routing_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Instance Statistics', 'routing' do + include RSpec::Rails::RequestExampleGroup + + it "routes '/-/instance_statistics' to conversational development index" do + expect(get('/-/instance_statistics')).to redirect_to('/-/instance_statistics/conversational_development_index') + end +end diff --git a/spec/support/shared_examples/instance_statistics_controllers_shared_examples.rb b/spec/support/shared_examples/instance_statistics_controllers_shared_examples.rb new file mode 100644 index 00000000000..5334af841e1 --- /dev/null +++ b/spec/support/shared_examples/instance_statistics_controllers_shared_examples.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +shared_examples 'instance statistics availability' do + let(:user) { create(:user) } + + before do + sign_in(user) + end + + describe 'GET #index' do + it 'is available when the feature is available publicly' do + get :index + + expect(response).to have_gitlab_http_status(:success) + end + + it 'renders a 404 when the feature is not available publicly' do + stub_application_setting(instance_statistics_visibility_private: true) + + get :index + + expect(response).to have_gitlab_http_status(:not_found) + end + + context 'for admins' do + let(:user) { create(:admin) } + + it 'allows access when the feature is not available publicly' do + stub_application_setting(instance_statistics_visibility_private: true) + + get :index + + expect(response).to have_gitlab_http_status(:success) + end + end + end +end |