diff options
Diffstat (limited to 'spec/controllers')
220 files changed, 2400 insertions, 1036 deletions
diff --git a/spec/controllers/abuse_reports_controller_spec.rb b/spec/controllers/abuse_reports_controller_spec.rb index 087b564dddb..da7577c371d 100644 --- a/spec/controllers/abuse_reports_controller_spec.rb +++ b/spec/controllers/abuse_reports_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AbuseReportsController do +RSpec.describe AbuseReportsController do let(:reporter) { create(:user) } let(:user) { create(:user) } let(:attrs) do diff --git a/spec/controllers/acme_challenges_controller_spec.rb b/spec/controllers/acme_challenges_controller_spec.rb index be077a4b20d..e737999fa2d 100644 --- a/spec/controllers/acme_challenges_controller_spec.rb +++ b/spec/controllers/acme_challenges_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AcmeChallengesController do +RSpec.describe AcmeChallengesController do describe '#show' do let!(:acme_order) { create(:pages_domain_acme_order) } diff --git a/spec/controllers/admin/appearances_controller_spec.rb b/spec/controllers/admin/appearances_controller_spec.rb index 621aa148301..ee6a4a4c7af 100644 --- a/spec/controllers/admin/appearances_controller_spec.rb +++ b/spec/controllers/admin/appearances_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::AppearancesController do +RSpec.describe Admin::AppearancesController do let(:admin) { create(:admin) } let(:header_message) { 'Header message' } let(:footer_message) { 'Footer' } diff --git a/spec/controllers/admin/application_settings_controller_spec.rb b/spec/controllers/admin/application_settings_controller_spec.rb index fe28e791ade..8ab29a72477 100644 --- a/spec/controllers/admin/application_settings_controller_spec.rb +++ b/spec/controllers/admin/application_settings_controller_spec.rb @@ -2,8 +2,9 @@ require 'spec_helper' -describe Admin::ApplicationSettingsController do +RSpec.describe Admin::ApplicationSettingsController do include StubENV + include UsageDataHelpers let(:group) { create(:group) } let(:project) { create(:project, namespace: group) } @@ -16,7 +17,7 @@ describe Admin::ApplicationSettingsController do describe 'GET #usage_data with no access' do before do - allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false) + stub_usage_data_connections sign_in(user) end @@ -29,7 +30,7 @@ describe Admin::ApplicationSettingsController do describe 'GET #usage_data' do before do - allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false) + stub_usage_data_connections sign_in(admin) end @@ -120,6 +121,13 @@ describe Admin::ApplicationSettingsController do expect(ApplicationSetting.current.namespace_storage_size_limit).not_to eq(-100) end + it 'updates repository_storages_weighted setting' do + put :update, params: { application_setting: { repository_storages_weighted_default: 75 } } + + expect(response).to redirect_to(general_admin_application_settings_path) + expect(ApplicationSetting.current.repository_storages_weighted_default).to eq(75) + end + context 'external policy classification settings' do let(:settings) do { diff --git a/spec/controllers/admin/applications_controller_spec.rb b/spec/controllers/admin/applications_controller_spec.rb index 163a2033b58..732d20666cb 100644 --- a/spec/controllers/admin/applications_controller_spec.rb +++ b/spec/controllers/admin/applications_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::ApplicationsController do +RSpec.describe Admin::ApplicationsController do let(:admin) { create(:admin) } let(:application) { create(:oauth_application, owner_id: nil, owner_type: nil) } diff --git a/spec/controllers/admin/ci/variables_controller_spec.rb b/spec/controllers/admin/ci/variables_controller_spec.rb index 57f2dd21f39..9f0a1bd3be1 100644 --- a/spec/controllers/admin/ci/variables_controller_spec.rb +++ b/spec/controllers/admin/ci/variables_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::Ci::VariablesController do +RSpec.describe Admin::Ci::VariablesController do let_it_be(:variable) { create(:ci_instance_variable) } before do diff --git a/spec/controllers/admin/clusters/applications_controller_spec.rb b/spec/controllers/admin/clusters/applications_controller_spec.rb index 44693505c4f..2a77693061c 100644 --- a/spec/controllers/admin/clusters/applications_controller_spec.rb +++ b/spec/controllers/admin/clusters/applications_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::Clusters::ApplicationsController do +RSpec.describe Admin::Clusters::ApplicationsController do include AccessMatchersForController def current_application diff --git a/spec/controllers/admin/clusters_controller_spec.rb b/spec/controllers/admin/clusters_controller_spec.rb index d4a12e0dc52..d899e86ae5f 100644 --- a/spec/controllers/admin/clusters_controller_spec.rb +++ b/spec/controllers/admin/clusters_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::ClustersController do +RSpec.describe Admin::ClustersController do include AccessMatchersForController include GoogleApi::CloudPlatformHelpers @@ -42,6 +42,13 @@ describe Admin::ClustersController do expect(response).to match_response_schema('cluster_list') end + it 'sets the polling interval header for json requests' do + get_index(format: :json) + + expect(response).to have_gitlab_http_status(:ok) + expect(response.headers['Poll-Interval']).to eq("10000") + end + context 'when page is specified' do let(:last_page) { Clusters::Cluster.instance_type.page.total_pages } let(:total_count) { Clusters::Cluster.instance_type.page.total_count } diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb index 4de69a9aea1..283d82a3ab8 100644 --- a/spec/controllers/admin/dashboard_controller_spec.rb +++ b/spec/controllers/admin/dashboard_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::DashboardController do +RSpec.describe Admin::DashboardController do describe '#index' do context 'with pending_delete projects' do render_views diff --git a/spec/controllers/admin/gitaly_servers_controller_spec.rb b/spec/controllers/admin/gitaly_servers_controller_spec.rb index db94ea06f59..53f8a06ab52 100644 --- a/spec/controllers/admin/gitaly_servers_controller_spec.rb +++ b/spec/controllers/admin/gitaly_servers_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::GitalyServersController do +RSpec.describe Admin::GitalyServersController do describe '#index' do before do sign_in(create(:admin)) diff --git a/spec/controllers/admin/groups_controller_spec.rb b/spec/controllers/admin/groups_controller_spec.rb index 1123563c1e3..3f32209543f 100644 --- a/spec/controllers/admin/groups_controller_spec.rb +++ b/spec/controllers/admin/groups_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::GroupsController do +RSpec.describe Admin::GroupsController do let(:group) { create(:group) } let(:project) { create(:project, namespace: group) } let(:admin) { create(:admin) } diff --git a/spec/controllers/admin/health_check_controller_spec.rb b/spec/controllers/admin/health_check_controller_spec.rb index cf5b27156c0..06aace429e3 100644 --- a/spec/controllers/admin/health_check_controller_spec.rb +++ b/spec/controllers/admin/health_check_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::HealthCheckController do +RSpec.describe Admin::HealthCheckController do let(:admin) { create(:admin) } before do diff --git a/spec/controllers/admin/hooks_controller_spec.rb b/spec/controllers/admin/hooks_controller_spec.rb index 9973ef93cd9..8975f746dd7 100644 --- a/spec/controllers/admin/hooks_controller_spec.rb +++ b/spec/controllers/admin/hooks_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::HooksController do +RSpec.describe Admin::HooksController do let(:admin) { create(:admin) } before do diff --git a/spec/controllers/admin/identities_controller_spec.rb b/spec/controllers/admin/identities_controller_spec.rb index f483c88d18d..6ac5ce13884 100644 --- a/spec/controllers/admin/identities_controller_spec.rb +++ b/spec/controllers/admin/identities_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::IdentitiesController do +RSpec.describe Admin::IdentitiesController do let(:admin) { create(:admin) } before do diff --git a/spec/controllers/admin/impersonations_controller_spec.rb b/spec/controllers/admin/impersonations_controller_spec.rb index fa3923bca8c..326003acaf8 100644 --- a/spec/controllers/admin/impersonations_controller_spec.rb +++ b/spec/controllers/admin/impersonations_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::ImpersonationsController do +RSpec.describe Admin::ImpersonationsController do let(:impersonator) { create(:admin) } let(:user) { create(:user) } diff --git a/spec/controllers/admin/integrations_controller_spec.rb b/spec/controllers/admin/integrations_controller_spec.rb index 817223bd91a..7e7b60db2dc 100644 --- a/spec/controllers/admin/integrations_controller_spec.rb +++ b/spec/controllers/admin/integrations_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::IntegrationsController do +RSpec.describe Admin::IntegrationsController do let(:admin) { create(:admin) } before do @@ -36,7 +36,9 @@ describe Admin::IntegrationsController do let(:integration) { create(:jira_service, :instance) } before do - put :update, params: { id: integration.class.to_param, service: { url: url } } + allow(PropagateIntegrationWorker).to receive(:perform_async) + + put :update, params: { id: integration.class.to_param, overwrite: true, service: { url: url } } end context 'valid params' do @@ -46,6 +48,10 @@ describe Admin::IntegrationsController do expect(response).to have_gitlab_http_status(:found) expect(integration.reload.url).to eq(url) end + + it 'calls to PropagateIntegrationWorker' do + expect(PropagateIntegrationWorker).to have_received(:perform_async).with(integration.id, true) + end end context 'invalid params' do @@ -56,6 +62,10 @@ describe Admin::IntegrationsController do expect(response).to render_template(:edit) expect(integration.reload.url).not_to eq(url) end + + it 'does not call to PropagateIntegrationWorker' do + expect(PropagateIntegrationWorker).not_to have_received(:perform_async) + end end end end diff --git a/spec/controllers/admin/projects_controller_spec.rb b/spec/controllers/admin/projects_controller_spec.rb index f0157fb4260..b5f411c9121 100644 --- a/spec/controllers/admin/projects_controller_spec.rb +++ b/spec/controllers/admin/projects_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::ProjectsController do +RSpec.describe Admin::ProjectsController do let!(:project) { create(:project, :public) } before do diff --git a/spec/controllers/admin/requests_profiles_controller_spec.rb b/spec/controllers/admin/requests_profiles_controller_spec.rb index 629233b04e7..7ee46b5b28a 100644 --- a/spec/controllers/admin/requests_profiles_controller_spec.rb +++ b/spec/controllers/admin/requests_profiles_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::RequestsProfilesController do +RSpec.describe Admin::RequestsProfilesController do let_it_be(:admin) { create(:admin) } before do diff --git a/spec/controllers/admin/runners_controller_spec.rb b/spec/controllers/admin/runners_controller_spec.rb index 803fcf90135..013eee19409 100644 --- a/spec/controllers/admin/runners_controller_spec.rb +++ b/spec/controllers/admin/runners_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::RunnersController do +RSpec.describe Admin::RunnersController do let_it_be(:runner) { create(:ci_runner) } before do diff --git a/spec/controllers/admin/serverless/domains_controller_spec.rb b/spec/controllers/admin/serverless/domains_controller_spec.rb index 43c3f0117bc..e7503fb37fa 100644 --- a/spec/controllers/admin/serverless/domains_controller_spec.rb +++ b/spec/controllers/admin/serverless/domains_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::Serverless::DomainsController do +RSpec.describe Admin::Serverless::DomainsController do let(:admin) { create(:admin) } let(:user) { create(:user) } diff --git a/spec/controllers/admin/services_controller_spec.rb b/spec/controllers/admin/services_controller_spec.rb index 5dde0d57293..2ad4989af4f 100644 --- a/spec/controllers/admin/services_controller_spec.rb +++ b/spec/controllers/admin/services_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::ServicesController do +RSpec.describe Admin::ServicesController do let(:admin) { create(:admin) } before do diff --git a/spec/controllers/admin/sessions_controller_spec.rb b/spec/controllers/admin/sessions_controller_spec.rb index 351148dbc65..82366cc6952 100644 --- a/spec/controllers/admin/sessions_controller_spec.rb +++ b/spec/controllers/admin/sessions_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::SessionsController, :do_not_mock_admin_mode do +RSpec.describe Admin::SessionsController, :do_not_mock_admin_mode do include_context 'custom session' let(:user) { create(:user) } diff --git a/spec/controllers/admin/spam_logs_controller_spec.rb b/spec/controllers/admin/spam_logs_controller_spec.rb index ec0d8c47660..13038339d08 100644 --- a/spec/controllers/admin/spam_logs_controller_spec.rb +++ b/spec/controllers/admin/spam_logs_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::SpamLogsController do +RSpec.describe Admin::SpamLogsController do let(:admin) { create(:admin) } let(:user) { create(:user) } let!(:first_spam) { create(:spam_log, user: user) } diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 7a7201a6454..08a1d7c9fa9 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Admin::UsersController do +RSpec.describe Admin::UsersController do let(:user) { create(:user) } let_it_be(:admin) { create(:admin) } @@ -254,6 +254,18 @@ describe Admin::UsersController do errors = assigns[:user].errors expect(errors).to contain_exactly(errors.full_message(:email, I18n.t('errors.messages.invalid'))) end + + context 'admin notes' do + it 'creates the user with note' do + note = '2020-05-12 | Note | DCMA | Link' + user_params = attributes_for(:user, note: note) + + expect { post :create, params: { user: user_params } }.to change { User.count }.by(1) + + new_user = User.last + expect(new_user.note).to eq(note) + end + end end describe 'POST update' do @@ -338,6 +350,20 @@ describe Admin::UsersController do end end end + + context 'admin notes' do + it 'updates the note for the user' do + note = '2020-05-12 | Note | DCMA | Link' + params = { + id: user.to_param, + user: { + note: note + } + } + + expect { post :update, params: params }.to change { user.reload.note }.to(note) + end + end end describe "DELETE #remove_email" do diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index ed2e61d6cf6..4002b7aca63 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe ApplicationController do +RSpec.describe ApplicationController do include TermsHelper let(:user) { create(:user) } @@ -310,13 +310,6 @@ describe ApplicationController do expect(subject).to be_truthy end - - it 'returns true if user has signed up using omniauth-ultraauth' do - user = create(:omniauth_user, provider: 'ultraauth') - allow(controller).to receive(:current_user).and_return(user) - - expect(subject).to be_truthy - end end describe '#two_factor_grace_period' do diff --git a/spec/controllers/autocomplete_controller_spec.rb b/spec/controllers/autocomplete_controller_spec.rb index 7b1e9748268..aeb3f4dcb17 100644 --- a/spec/controllers/autocomplete_controller_spec.rb +++ b/spec/controllers/autocomplete_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AutocompleteController do +RSpec.describe AutocompleteController do let(:project) { create(:project) } let(:user) { project.owner } diff --git a/spec/controllers/boards/issues_controller_spec.rb b/spec/controllers/boards/issues_controller_spec.rb index 8639b76ef0f..601b8d427e0 100644 --- a/spec/controllers/boards/issues_controller_spec.rb +++ b/spec/controllers/boards/issues_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Boards::IssuesController do +RSpec.describe Boards::IssuesController do include ExternalAuthorizationServiceHelpers let(:project) { create(:project, :private) } diff --git a/spec/controllers/boards/lists_controller_spec.rb b/spec/controllers/boards/lists_controller_spec.rb index d0b34b55c36..c72d9e5053a 100644 --- a/spec/controllers/boards/lists_controller_spec.rb +++ b/spec/controllers/boards/lists_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Boards::ListsController do +RSpec.describe Boards::ListsController do let(:project) { create(:project) } let(:board) { create(:board, project: project) } let(:user) { create(:user) } diff --git a/spec/controllers/chaos_controller_spec.rb b/spec/controllers/chaos_controller_spec.rb index 5812990ce7a..550303d292a 100644 --- a/spec/controllers/chaos_controller_spec.rb +++ b/spec/controllers/chaos_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ChaosController do +RSpec.describe ChaosController do describe '#leakmem' do it 'calls synchronously' do expect(Gitlab::Chaos).to receive(:leak_mem).with(100, 30.seconds) diff --git a/spec/controllers/concerns/boards_responses_spec.rb b/spec/controllers/concerns/boards_responses_spec.rb index bdebdf94761..553a547d42c 100644 --- a/spec/controllers/concerns/boards_responses_spec.rb +++ b/spec/controllers/concerns/boards_responses_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe BoardsResponses do +RSpec.describe BoardsResponses do let(:controller_class) do Class.new do include BoardsResponses diff --git a/spec/controllers/concerns/checks_collaboration_spec.rb b/spec/controllers/concerns/checks_collaboration_spec.rb index 7187e239486..be8beff5dd6 100644 --- a/spec/controllers/concerns/checks_collaboration_spec.rb +++ b/spec/controllers/concerns/checks_collaboration_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ChecksCollaboration do +RSpec.describe ChecksCollaboration do include ProjectForksHelper let(:helper) do diff --git a/spec/controllers/concerns/confirm_email_warning_spec.rb b/spec/controllers/concerns/confirm_email_warning_spec.rb index 93e3423261c..24ee6fb30d2 100644 --- a/spec/controllers/concerns/confirm_email_warning_spec.rb +++ b/spec/controllers/concerns/confirm_email_warning_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ConfirmEmailWarning do +RSpec.describe ConfirmEmailWarning do before do stub_feature_flags(soft_email_confirmation: true) end diff --git a/spec/controllers/concerns/continue_params_spec.rb b/spec/controllers/concerns/continue_params_spec.rb index 6af01aa837c..c010e8ffbd0 100644 --- a/spec/controllers/concerns/continue_params_spec.rb +++ b/spec/controllers/concerns/continue_params_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ContinueParams do +RSpec.describe ContinueParams do let(:controller_class) do Class.new(ActionController::Base) do include ContinueParams diff --git a/spec/controllers/concerns/controller_with_cross_project_access_check_spec.rb b/spec/controllers/concerns/controller_with_cross_project_access_check_spec.rb index 3f9d690837b..a58b83dc42c 100644 --- a/spec/controllers/concerns/controller_with_cross_project_access_check_spec.rb +++ b/spec/controllers/concerns/controller_with_cross_project_access_check_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ControllerWithCrossProjectAccessCheck do +RSpec.describe ControllerWithCrossProjectAccessCheck do let(:user) { create(:user) } before do diff --git a/spec/controllers/concerns/enforces_admin_authentication_spec.rb b/spec/controllers/concerns/enforces_admin_authentication_spec.rb index 1809bb2d636..c6ad1a00484 100644 --- a/spec/controllers/concerns/enforces_admin_authentication_spec.rb +++ b/spec/controllers/concerns/enforces_admin_authentication_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe EnforcesAdminAuthentication do +RSpec.describe EnforcesAdminAuthentication do include AdminModeHelper let(:user) { create(:user) } diff --git a/spec/controllers/concerns/group_tree_spec.rb b/spec/controllers/concerns/group_tree_spec.rb index 543f0170be0..a0707688e54 100644 --- a/spec/controllers/concerns/group_tree_spec.rb +++ b/spec/controllers/concerns/group_tree_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GroupTree do +RSpec.describe GroupTree do let(:group) { create(:group, :public) } let(:user) { create(:user) } diff --git a/spec/controllers/concerns/import_url_params_spec.rb b/spec/controllers/concerns/import_url_params_spec.rb index 41e29d71386..72f13cdcc94 100644 --- a/spec/controllers/concerns/import_url_params_spec.rb +++ b/spec/controllers/concerns/import_url_params_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ImportUrlParams do +RSpec.describe ImportUrlParams do let(:import_url_params) do controller = OpenStruct.new(params: params).extend(described_class) controller.import_url_params diff --git a/spec/controllers/concerns/internal_redirect_spec.rb b/spec/controllers/concerns/internal_redirect_spec.rb index cc6422f2817..3741ff647e4 100644 --- a/spec/controllers/concerns/internal_redirect_spec.rb +++ b/spec/controllers/concerns/internal_redirect_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe InternalRedirect do +RSpec.describe InternalRedirect do let(:controller_class) do Class.new do include InternalRedirect diff --git a/spec/controllers/concerns/issuable_actions_spec.rb b/spec/controllers/concerns/issuable_actions_spec.rb index 2ab46992b99..c3fef591b91 100644 --- a/spec/controllers/concerns/issuable_actions_spec.rb +++ b/spec/controllers/concerns/issuable_actions_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe IssuableActions do +RSpec.describe IssuableActions do let(:project) { double('project') } let(:user) { double('user') } let(:issuable) { double('issuable') } diff --git a/spec/controllers/concerns/issuable_collections_spec.rb b/spec/controllers/concerns/issuable_collections_spec.rb index 7bdf5c49425..befdd760965 100644 --- a/spec/controllers/concerns/issuable_collections_spec.rb +++ b/spec/controllers/concerns/issuable_collections_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe IssuableCollections do +RSpec.describe IssuableCollections do let(:user) { create(:user) } let(:controller) do diff --git a/spec/controllers/concerns/lfs_request_spec.rb b/spec/controllers/concerns/lfs_request_spec.rb index f771a3438cf..3bafd761a3e 100644 --- a/spec/controllers/concerns/lfs_request_spec.rb +++ b/spec/controllers/concerns/lfs_request_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe LfsRequest do +RSpec.describe LfsRequest do include ProjectForksHelper controller(Repositories::GitHttpClientController) do diff --git a/spec/controllers/concerns/metrics_dashboard_spec.rb b/spec/controllers/concerns/metrics_dashboard_spec.rb index e2fa03670d9..39ddf687dca 100644 --- a/spec/controllers/concerns/metrics_dashboard_spec.rb +++ b/spec/controllers/concerns/metrics_dashboard_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe MetricsDashboard do +RSpec.describe MetricsDashboard do include MetricsDashboardHelpers describe 'GET #metrics_dashboard' do @@ -134,7 +134,7 @@ describe MetricsDashboard do it 'adds starred dashboard information and sorts the list' do all_dashboards = json_response['all_dashboards'].map { |dashboard| dashboard.slice('display_name', 'starred', 'user_starred_path') } expected_response = [ - { "display_name" => "Default", "starred" => false, 'user_starred_path' => api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: 'config/prometheus/common_metrics.yml' }) }, + { "display_name" => "Default dashboard", "starred" => false, 'user_starred_path' => api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: 'config/prometheus/common_metrics.yml' }) }, { "display_name" => "anomaly.yml", "starred" => false, 'user_starred_path' => api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: '.gitlab/dashboards/anomaly.yml' }) }, { "display_name" => "errors.yml", "starred" => true, 'user_starred_path' => api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: '.gitlab/dashboards/errors.yml' }) }, { "display_name" => "test.yml", "starred" => true, 'user_starred_path' => api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: '.gitlab/dashboards/test.yml' }) } diff --git a/spec/controllers/concerns/page_limiter_spec.rb b/spec/controllers/concerns/page_limiter_spec.rb index 287b62cb66c..a4177943c05 100644 --- a/spec/controllers/concerns/page_limiter_spec.rb +++ b/spec/controllers/concerns/page_limiter_spec.rb @@ -14,7 +14,7 @@ class PageLimiterSpecController < ApplicationController end end -describe PageLimiter do +RSpec.describe PageLimiter do let(:controller_class) do PageLimiterSpecController end diff --git a/spec/controllers/concerns/project_unauthorized_spec.rb b/spec/controllers/concerns/project_unauthorized_spec.rb index 9b40660811e..4fce160cdaf 100644 --- a/spec/controllers/concerns/project_unauthorized_spec.rb +++ b/spec/controllers/concerns/project_unauthorized_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ProjectUnauthorized do +RSpec.describe ProjectUnauthorized do include ExternalAuthorizationServiceHelpers let(:user) { create(:user) } diff --git a/spec/controllers/concerns/redirects_for_missing_path_on_tree_spec.rb b/spec/controllers/concerns/redirects_for_missing_path_on_tree_spec.rb index 903100ba93f..5c3b6e13ee3 100644 --- a/spec/controllers/concerns/redirects_for_missing_path_on_tree_spec.rb +++ b/spec/controllers/concerns/redirects_for_missing_path_on_tree_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe RedirectsForMissingPathOnTree, type: :controller do +RSpec.describe RedirectsForMissingPathOnTree, type: :controller do controller(ActionController::Base) do include Gitlab::Routing.url_helpers include RedirectsForMissingPathOnTree diff --git a/spec/controllers/concerns/renders_commits_spec.rb b/spec/controllers/concerns/renders_commits_spec.rb index c43ceb6b795..0bffb39d608 100644 --- a/spec/controllers/concerns/renders_commits_spec.rb +++ b/spec/controllers/concerns/renders_commits_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe RendersCommits do +RSpec.describe RendersCommits do let_it_be(:project) { create(:project, :public, :repository) } let_it_be(:merge_request) { create(:merge_request, source_project: project) } let_it_be(:user) { create(:user) } diff --git a/spec/controllers/concerns/routable_actions_spec.rb b/spec/controllers/concerns/routable_actions_spec.rb index 80c67022219..f28f990ecbb 100644 --- a/spec/controllers/concerns/routable_actions_spec.rb +++ b/spec/controllers/concerns/routable_actions_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe RoutableActions do +RSpec.describe RoutableActions do controller(::ApplicationController) do include RoutableActions diff --git a/spec/controllers/concerns/send_file_upload_spec.rb b/spec/controllers/concerns/send_file_upload_spec.rb index 3cfb7b5a488..7cfaf1b248f 100644 --- a/spec/controllers/concerns/send_file_upload_spec.rb +++ b/spec/controllers/concerns/send_file_upload_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe SendFileUpload do +RSpec.describe SendFileUpload do let(:uploader_class) do Class.new(GitlabUploader) do include ObjectStorage::Concern diff --git a/spec/controllers/concerns/sorting_preference_spec.rb b/spec/controllers/concerns/sorting_preference_spec.rb index a36124c6776..4f9506d4675 100644 --- a/spec/controllers/concerns/sorting_preference_spec.rb +++ b/spec/controllers/concerns/sorting_preference_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe SortingPreference do +RSpec.describe SortingPreference do let(:user) { create(:user) } let(:controller_class) do diff --git a/spec/controllers/concerns/sourcegraph_decorator_spec.rb b/spec/controllers/concerns/sourcegraph_decorator_spec.rb index f1f3f0489c6..2fca5a606d8 100644 --- a/spec/controllers/concerns/sourcegraph_decorator_spec.rb +++ b/spec/controllers/concerns/sourcegraph_decorator_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe SourcegraphDecorator do +RSpec.describe SourcegraphDecorator do let_it_be(:enabled_user) { create(:user, sourcegraph_enabled: true) } let_it_be(:disabled_user) { create(:user, sourcegraph_enabled: false) } let_it_be(:public_project) { create(:project, :public) } @@ -25,7 +25,7 @@ describe SourcegraphDecorator do end before do - Feature.get(:sourcegraph).enable(feature_enabled) + stub_feature_flags(sourcegraph: feature_enabled) stub_application_setting(sourcegraph_url: sourcegraph_url, sourcegraph_enabled: sourcegraph_enabled, sourcegraph_public_only: sourcegraph_public_only) @@ -36,10 +36,6 @@ describe SourcegraphDecorator do sign_in user if user end - after do - Feature.get(:sourcegraph).disable - end - subject do get :index, format: format diff --git a/spec/controllers/concerns/static_object_external_storage_spec.rb b/spec/controllers/concerns/static_object_external_storage_spec.rb index d3ece587ef7..afb43d531c0 100644 --- a/spec/controllers/concerns/static_object_external_storage_spec.rb +++ b/spec/controllers/concerns/static_object_external_storage_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe StaticObjectExternalStorage do +RSpec.describe StaticObjectExternalStorage do controller(Projects::ApplicationController) do include StaticObjectExternalStorage diff --git a/spec/controllers/dashboard/groups_controller_spec.rb b/spec/controllers/dashboard/groups_controller_spec.rb index b615bcc1e6b..f246d7bcaf1 100644 --- a/spec/controllers/dashboard/groups_controller_spec.rb +++ b/spec/controllers/dashboard/groups_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Dashboard::GroupsController do +RSpec.describe Dashboard::GroupsController do include ExternalAuthorizationServiceHelpers let(:user) { create(:user) } diff --git a/spec/controllers/dashboard/labels_controller_spec.rb b/spec/controllers/dashboard/labels_controller_spec.rb index cb9c3660b9b..415cb821545 100644 --- a/spec/controllers/dashboard/labels_controller_spec.rb +++ b/spec/controllers/dashboard/labels_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Dashboard::LabelsController do +RSpec.describe Dashboard::LabelsController do let(:project) { create(:project) } let(:user) { create(:user) } let!(:label) { create(:label, project: project) } diff --git a/spec/controllers/dashboard/milestones_controller_spec.rb b/spec/controllers/dashboard/milestones_controller_spec.rb index f4b04ad6dee..899aa7a41c1 100644 --- a/spec/controllers/dashboard/milestones_controller_spec.rb +++ b/spec/controllers/dashboard/milestones_controller_spec.rb @@ -2,18 +2,13 @@ require 'spec_helper' -describe Dashboard::MilestonesController do +RSpec.describe Dashboard::MilestonesController do let(:project) { create(:project) } let(:group) { create(:group) } let(:user) { create(:user) } let(:project_milestone) { create(:milestone, project: project) } let(:group_milestone) { create(:milestone, group: group) } - let(:milestone) do - DashboardMilestone.build( - [project], - project_milestone.title - ) - end + let(:milestone) { create(:milestone, group: group) } let(:issue) { create(:issue, project: project, milestone: project_milestone) } let(:group_issue) { create(:issue, milestone: group_milestone, project: create(:project, group: group)) } @@ -28,22 +23,6 @@ describe Dashboard::MilestonesController do group.add_developer(user) end - it_behaves_like 'milestone tabs' - - describe "#show" do - render_views - - def view_milestone - get :show, params: { id: milestone.safe_title, title: milestone.title } - end - - it 'shows milestone page' do - view_milestone - - expect(response).to have_gitlab_http_status(:ok) - end - end - describe "#index" do let(:public_group) { create(:group, :public) } let!(:public_milestone) { create(:milestone, group: public_group) } @@ -58,7 +37,6 @@ describe Dashboard::MilestonesController do expect(response).to have_gitlab_http_status(:ok) expect(json_response.size).to eq(2) expect(json_response.map { |i| i["name"] }).to match_array([group_milestone.name, project_milestone.name]) - expect(json_response.map { |i| i["group_name"] }.compact).to match_array(group.name) end it 'returns closed group and project milestones to which the user belongs' do @@ -67,7 +45,6 @@ describe Dashboard::MilestonesController do expect(response).to have_gitlab_http_status(:ok) expect(json_response.size).to eq(2) expect(json_response.map { |i| i["name"] }).to match_array([closed_group_milestone.name, closed_project_milestone.name]) - expect(json_response.map { |i| i["group_name"] }.compact).to match_array(group.name) end it 'searches legacy project milestones by title when search_title is given' do diff --git a/spec/controllers/dashboard/projects_controller_spec.rb b/spec/controllers/dashboard/projects_controller_spec.rb index eeac696c3f2..ee043fde0ff 100644 --- a/spec/controllers/dashboard/projects_controller_spec.rb +++ b/spec/controllers/dashboard/projects_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Dashboard::ProjectsController do +RSpec.describe Dashboard::ProjectsController do include ExternalAuthorizationServiceHelpers describe '#index' do diff --git a/spec/controllers/dashboard/snippets_controller_spec.rb b/spec/controllers/dashboard/snippets_controller_spec.rb index d5e3a348cd2..3c316d07408 100644 --- a/spec/controllers/dashboard/snippets_controller_spec.rb +++ b/spec/controllers/dashboard/snippets_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Dashboard::SnippetsController do +RSpec.describe Dashboard::SnippetsController do let(:user) { create(:user) } before do diff --git a/spec/controllers/dashboard/todos_controller_spec.rb b/spec/controllers/dashboard/todos_controller_spec.rb index 004eef1873e..f0aa351bee0 100644 --- a/spec/controllers/dashboard/todos_controller_spec.rb +++ b/spec/controllers/dashboard/todos_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Dashboard::TodosController do +RSpec.describe Dashboard::TodosController do let(:user) { create(:user) } let(:author) { create(:user) } let(:project) { create(:project) } diff --git a/spec/controllers/dashboard_controller_spec.rb b/spec/controllers/dashboard_controller_spec.rb index a280d829d83..d27817c0a82 100644 --- a/spec/controllers/dashboard_controller_spec.rb +++ b/spec/controllers/dashboard_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DashboardController do +RSpec.describe DashboardController do context 'signed in' do let(:user) { create(:user) } let(:project) { create(:project) } diff --git a/spec/controllers/explore/groups_controller_spec.rb b/spec/controllers/explore/groups_controller_spec.rb index eccbd7fa14d..310fe609cf1 100644 --- a/spec/controllers/explore/groups_controller_spec.rb +++ b/spec/controllers/explore/groups_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Explore::GroupsController do +RSpec.describe Explore::GroupsController do let(:user) { create(:user) } before do diff --git a/spec/controllers/explore/projects_controller_spec.rb b/spec/controllers/explore/projects_controller_spec.rb index 00cc2d5a81c..fd86501ff5d 100644 --- a/spec/controllers/explore/projects_controller_spec.rb +++ b/spec/controllers/explore/projects_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Explore::ProjectsController do +RSpec.describe Explore::ProjectsController do shared_examples 'explore projects' do describe 'GET #index.json' do render_views diff --git a/spec/controllers/explore/snippets_controller_spec.rb b/spec/controllers/explore/snippets_controller_spec.rb index ab91faa6cef..f7bd2ba917e 100644 --- a/spec/controllers/explore/snippets_controller_spec.rb +++ b/spec/controllers/explore/snippets_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Explore::SnippetsController do +RSpec.describe Explore::SnippetsController do describe 'GET #index' do let!(:project_snippet) { create_list(:project_snippet, 3, :public) } let!(:personal_snippet) { create_list(:personal_snippet, 3, :public) } diff --git a/spec/controllers/google_api/authorizations_controller_spec.rb b/spec/controllers/google_api/authorizations_controller_spec.rb index 9d0e0d92978..3dd2cc307d5 100644 --- a/spec/controllers/google_api/authorizations_controller_spec.rb +++ b/spec/controllers/google_api/authorizations_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GoogleApi::AuthorizationsController do +RSpec.describe GoogleApi::AuthorizationsController do describe 'GET|POST #callback' do let(:user) { create(:user) } let(:token) { 'token' } diff --git a/spec/controllers/graphql_controller_spec.rb b/spec/controllers/graphql_controller_spec.rb index 68150504fe3..c5643f96b7a 100644 --- a/spec/controllers/graphql_controller_spec.rb +++ b/spec/controllers/graphql_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GraphqlController do +RSpec.describe GraphqlController do include GraphqlHelpers before do diff --git a/spec/controllers/groups/avatars_controller_spec.rb b/spec/controllers/groups/avatars_controller_spec.rb index 1229328000b..18b116831b2 100644 --- a/spec/controllers/groups/avatars_controller_spec.rb +++ b/spec/controllers/groups/avatars_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::AvatarsController do +RSpec.describe Groups::AvatarsController do include ExternalAuthorizationServiceHelpers let(:user) { create(:user) } diff --git a/spec/controllers/groups/boards_controller_spec.rb b/spec/controllers/groups/boards_controller_spec.rb index b556af0eedc..66595c27531 100644 --- a/spec/controllers/groups/boards_controller_spec.rb +++ b/spec/controllers/groups/boards_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::BoardsController do +RSpec.describe Groups::BoardsController do let(:group) { create(:group) } let(:user) { create(:user) } diff --git a/spec/controllers/groups/children_controller_spec.rb b/spec/controllers/groups/children_controller_spec.rb index a8921300e6b..e97fe50c468 100644 --- a/spec/controllers/groups/children_controller_spec.rb +++ b/spec/controllers/groups/children_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::ChildrenController do +RSpec.describe Groups::ChildrenController do include ExternalAuthorizationServiceHelpers let(:group) { create(:group, :public) } diff --git a/spec/controllers/groups/clusters/applications_controller_spec.rb b/spec/controllers/groups/clusters/applications_controller_spec.rb index bab9e64cfdb..c1d170edce3 100644 --- a/spec/controllers/groups/clusters/applications_controller_spec.rb +++ b/spec/controllers/groups/clusters/applications_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::Clusters::ApplicationsController do +RSpec.describe Groups::Clusters::ApplicationsController do include AccessMatchersForController def current_application diff --git a/spec/controllers/groups/clusters_controller_spec.rb b/spec/controllers/groups/clusters_controller_spec.rb index 1f2f6bd811b..6765cf0990a 100644 --- a/spec/controllers/groups/clusters_controller_spec.rb +++ b/spec/controllers/groups/clusters_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::ClustersController do +RSpec.describe Groups::ClustersController do include AccessMatchersForController include GoogleApi::CloudPlatformHelpers @@ -47,6 +47,13 @@ describe Groups::ClustersController do expect(response).to match_response_schema('cluster_list') end + it 'sets the polling interval header for json requests' do + go(format: :json) + + expect(response).to have_gitlab_http_status(:ok) + expect(response.headers['Poll-Interval']).to eq("10000") + end + context 'when page is specified' do let(:last_page) { group.clusters.page.total_pages } let(:total_count) { group.clusters.page.total_count } diff --git a/spec/controllers/groups/group_links_controller_spec.rb b/spec/controllers/groups/group_links_controller_spec.rb index ca430414d17..07299382230 100644 --- a/spec/controllers/groups/group_links_controller_spec.rb +++ b/spec/controllers/groups/group_links_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::GroupLinksController do +RSpec.describe Groups::GroupLinksController do let(:shared_with_group) { create(:group, :private) } let(:shared_group) { create(:group, :private) } let(:user) { create(:user) } diff --git a/spec/controllers/groups/group_members_controller_spec.rb b/spec/controllers/groups/group_members_controller_spec.rb index f69d0602404..85f1b247ee9 100644 --- a/spec/controllers/groups/group_members_controller_spec.rb +++ b/spec/controllers/groups/group_members_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::GroupMembersController do +RSpec.describe Groups::GroupMembersController do include ExternalAuthorizationServiceHelpers let(:user) { create(:user) } diff --git a/spec/controllers/groups/imports_controller_spec.rb b/spec/controllers/groups/imports_controller_spec.rb new file mode 100644 index 00000000000..eb43a62b75b --- /dev/null +++ b/spec/controllers/groups/imports_controller_spec.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Groups::ImportsController do + describe 'GET #show' do + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group, :private) } + + context 'when the user has permission to view the group' do + before do + sign_in(user) + group.add_maintainer(user) + end + + context 'when the import is in progress' do + before do + create(:group_import_state, group: group) + end + + it 'renders the show template' do + get :show, params: { group_id: group } + + expect(response).to render_template :show + end + + it 'sets the flash notice' do + get :show, params: { group_id: group, continue: { to: '/', notice_now: 'In progress' } } + + expect(flash.now[:notice]).to eq 'In progress' + end + end + + context 'when the import has failed' do + before do + create(:group_import_state, :failed, group: group) + end + + it 'redirects to the new group path' do + get :show, params: { group_id: group } + + expect(response).to redirect_to new_group_path(group) + end + + it 'sets a flash error' do + get :show, params: { group_id: group } + + expect(flash[:alert]).to eq 'Failed to import group.' + end + end + + context 'when the import has finished' do + before do + create(:group_import_state, :finished, group: group) + end + + it 'redirects to the group page' do + get :show, params: { group_id: group } + + expect(response).to redirect_to group_path(group) + end + end + + context 'when there is no import state' do + it 'redirects to the group page' do + get :show, params: { group_id: group } + + expect(response).to redirect_to group_path(group) + end + end + end + + context 'when the user does not have permission to view the group' do + before do + sign_in(user) + end + + it 'returns a 404' do + get :show, params: { group_id: group } + + expect(response).to have_gitlab_http_status :not_found + end + end + end +end diff --git a/spec/controllers/groups/labels_controller_spec.rb b/spec/controllers/groups/labels_controller_spec.rb index 90f91a4ff72..20ee19b01d1 100644 --- a/spec/controllers/groups/labels_controller_spec.rb +++ b/spec/controllers/groups/labels_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::LabelsController do +RSpec.describe Groups::LabelsController do let_it_be(:group) { create(:group) } let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, namespace: group) } diff --git a/spec/controllers/groups/milestones_controller_spec.rb b/spec/controllers/groups/milestones_controller_spec.rb index afb950bc538..e47bb75af22 100644 --- a/spec/controllers/groups/milestones_controller_spec.rb +++ b/spec/controllers/groups/milestones_controller_spec.rb @@ -2,21 +2,13 @@ require 'spec_helper' -describe Groups::MilestonesController do +RSpec.describe Groups::MilestonesController do let(:group) { create(:group, :public) } let!(:project) { create(:project, :public, group: group) } let!(:project2) { create(:project, group: group) } let(:user) { create(:user) } let(:title) { '肯定不是中文的问题' } - let(:milestone) do - project_milestone = create(:milestone, project: project) - - GroupMilestone.build( - group, - [project], - project_milestone.title - ) - end + let(:milestone) { create(:milestone, project: project) } let(:milestone_path) { group_milestone_path(group, milestone.safe_title, title: milestone.title) } let(:milestone_params) do @@ -168,17 +160,16 @@ describe Groups::MilestonesController do context 'as JSON' do let!(:milestone) { create(:milestone, group: group, title: 'group milestone') } - let!(:legacy_milestone1) { create(:milestone, project: project, title: 'legacy') } - let!(:legacy_milestone2) { create(:milestone, project: project2, title: 'legacy') } + let!(:project_milestone1) { create(:milestone, project: project, title: 'same name') } + let!(:project_milestone2) { create(:milestone, project: project2, title: 'same name') } - it 'lists legacy group milestones and group milestones' do + it 'lists project and group milestones' do get :index, params: { group_id: group.to_param }, format: :json milestones = json_response - expect(milestones.count).to eq(2) - expect(milestones.first["title"]).to eq("group milestone") - expect(milestones.second["title"]).to eq("legacy") + expect(milestones.count).to eq(3) + expect(milestones.collect { |m| m['title'] }).to match_array(['same name', 'same name', 'group milestone']) expect(response).to have_gitlab_http_status(:ok) expect(response.content_type).to eq 'application/json' end @@ -191,8 +182,9 @@ describe Groups::MilestonesController do get :index, params: { group_id: group.to_param }, format: :json milestones = json_response - expect(milestones.count).to eq(3) - expect(milestones.second["title"]).to eq("subgroup milestone") + milestone_titles = milestones.map { |m| m['title'] } + expect(milestones.count).to eq(4) + expect(milestone_titles).to match_array(['same name', 'same name', 'group milestone', 'subgroup milestone']) end end @@ -218,31 +210,18 @@ describe Groups::MilestonesController do end describe '#show' do - let(:milestone1) { create(:milestone, project: project, title: 'legacy') } - let(:milestone2) { create(:milestone, project: project, title: 'legacy') } - let(:group_milestone) { create(:milestone, group: group) } + render_views - context 'when there is a title parameter' do - it 'searches for a legacy group milestone' do - expect(GroupMilestone).to receive(:build) - expect(Milestone).not_to receive(:find_by_iid) + let!(:group_milestone) { create(:milestone, group: group) } - get :show, params: { group_id: group.to_param, id: title, title: milestone1.safe_title } - end - end + it 'renders for a group milestone' do + get :show, params: { group_id: group.to_param, id: group_milestone.iid } - context 'when there is not a title parameter' do - it 'searches for a group milestone' do - expect(GlobalMilestone).not_to receive(:build) - expect(Milestone).to receive(:find_by_iid) - - get :show, params: { group_id: group.to_param, id: group_milestone.id } - end + expect(response).to have_gitlab_http_status(:ok) + expect(response.body).to include(group_milestone.title) end end - it_behaves_like 'milestone tabs' - describe "#create" do it "creates group milestone with Chinese title" do post :create, @@ -277,34 +256,6 @@ describe Groups::MilestonesController do expect(response).to redirect_to(group_milestone_path(group, milestone.iid)) expect(milestone.title).to eq("title changed") end - - context "legacy group milestones" do - let!(:milestone1) { create(:milestone, project: project, title: 'legacy milestone', description: "old description") } - let!(:milestone2) { create(:milestone, project: project2, title: 'legacy milestone', description: "old description") } - - it "updates only group milestones state" do - milestone_params[:title] = "title changed" - milestone_params[:description] = "description changed" - milestone_params[:state_event] = "close" - - put :update, - params: { - id: milestone1.title.to_slug.to_s, - group_id: group.to_param, - milestone: milestone_params, - title: milestone1.title - } - - expect(response).to redirect_to(group_milestone_path(group, milestone1.safe_title, title: milestone1.title)) - - [milestone1, milestone2].each do |milestone| - milestone.reload - expect(milestone.title).to eq("legacy milestone") - expect(milestone.description).to eq("old description") - expect(milestone.state).to eq("closed") - end - end - end end describe "#destroy" do diff --git a/spec/controllers/groups/registry/repositories_controller_spec.rb b/spec/controllers/groups/registry/repositories_controller_spec.rb index 7b78aeadbd8..ddac8fc5002 100644 --- a/spec/controllers/groups/registry/repositories_controller_spec.rb +++ b/spec/controllers/groups/registry/repositories_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::Registry::RepositoriesController do +RSpec.describe Groups::Registry::RepositoriesController do let_it_be(:user) { create(:user) } let_it_be(:guest) { create(:user) } let_it_be(:group, reload: true) { create(:group) } @@ -17,6 +17,7 @@ describe Groups::Registry::RepositoriesController do before do stub_container_registry_config(enabled: true) + stub_container_registry_tags(repository: :any, tags: []) group.add_owner(user) group.add_guest(guest) sign_in(user) diff --git a/spec/controllers/groups/runners_controller_spec.rb b/spec/controllers/groups/runners_controller_spec.rb index bf556078eec..376cd569952 100644 --- a/spec/controllers/groups/runners_controller_spec.rb +++ b/spec/controllers/groups/runners_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::RunnersController do +RSpec.describe Groups::RunnersController do let(:user) { create(:user) } let(:group) { create(:group) } let(:runner) { create(:ci_runner, :group, groups: [group]) } diff --git a/spec/controllers/groups/settings/ci_cd_controller_spec.rb b/spec/controllers/groups/settings/ci_cd_controller_spec.rb index 45d62a7e6cf..55c19de4aa1 100644 --- a/spec/controllers/groups/settings/ci_cd_controller_spec.rb +++ b/spec/controllers/groups/settings/ci_cd_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::Settings::CiCdController do +RSpec.describe Groups::Settings::CiCdController do include ExternalAuthorizationServiceHelpers let(:group) { create(:group) } diff --git a/spec/controllers/groups/settings/integrations_controller_spec.rb b/spec/controllers/groups/settings/integrations_controller_spec.rb index 29c93c621bd..d079f3f077e 100644 --- a/spec/controllers/groups/settings/integrations_controller_spec.rb +++ b/spec/controllers/groups/settings/integrations_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::Settings::IntegrationsController do +RSpec.describe Groups::Settings::IntegrationsController do let_it_be(:project) { create(:project) } let(:user) { create(:user) } let(:group) { create(:group) } diff --git a/spec/controllers/groups/settings/repository_controller_spec.rb b/spec/controllers/groups/settings/repository_controller_spec.rb index 9523d404538..6d0caf6d655 100644 --- a/spec/controllers/groups/settings/repository_controller_spec.rb +++ b/spec/controllers/groups/settings/repository_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::Settings::RepositoryController do +RSpec.describe Groups::Settings::RepositoryController do include ExternalAuthorizationServiceHelpers let(:group) { create(:group) } diff --git a/spec/controllers/groups/shared_projects_controller_spec.rb b/spec/controllers/groups/shared_projects_controller_spec.rb index a31b5682ae0..dafce094b14 100644 --- a/spec/controllers/groups/shared_projects_controller_spec.rb +++ b/spec/controllers/groups/shared_projects_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::SharedProjectsController do +RSpec.describe Groups::SharedProjectsController do def get_shared_projects(params = {}) get :index, params: params.reverse_merge(format: :json, group_id: group.full_path) end diff --git a/spec/controllers/groups/uploads_controller_spec.rb b/spec/controllers/groups/uploads_controller_spec.rb index 8abebd04e8b..ea6a5ce8841 100644 --- a/spec/controllers/groups/uploads_controller_spec.rb +++ b/spec/controllers/groups/uploads_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::UploadsController do +RSpec.describe Groups::UploadsController do include WorkhorseHelpers let(:model) { create(:group, :public) } diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index d6c790ae7b8..e2a14165cb4 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::VariablesController do +RSpec.describe Groups::VariablesController do include ExternalAuthorizationServiceHelpers let(:group) { create(:group) } diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 354c9e047c8..dce7105c073 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GroupsController do +RSpec.describe GroupsController do include ExternalAuthorizationServiceHelpers let(:user) { create(:user) } @@ -37,6 +37,8 @@ describe GroupsController do end shared_examples 'details view' do + let(:namespace) { group } + it { is_expected.to render_template('groups/show') } context 'as atom' do @@ -50,6 +52,8 @@ describe GroupsController do expect(assigns(:events).map(&:id)).to contain_exactly(event.id) end end + + it_behaves_like 'namespace storage limit alert' end describe 'GET #show' do @@ -62,7 +66,19 @@ describe GroupsController do subject { get :show, params: { id: group.to_param }, format: format } - it_behaves_like 'details view' + context 'when the group is not importing' do + it_behaves_like 'details view' + end + + context 'when the group is importing' do + before do + create(:group_import_state, group: group) + end + + it 'redirects to the import status page' do + expect(subject).to redirect_to group_import_path(group) + end + end end describe 'GET #details' do @@ -301,6 +317,66 @@ describe GroupsController do end end end + + describe 'tracking group creation for onboarding issues experiment' do + before do + sign_in(user) + end + + subject(:create_namespace) { post :create, params: { group: { name: 'new_group', path: 'new_group' } } } + + context 'experiment disabled' do + before do + stub_experiment(onboarding_issues: false) + end + + it 'does not track anything' do + expect(Gitlab::Tracking).not_to receive(:event) + + create_namespace + end + end + + context 'experiment enabled' do + before do + stub_experiment(onboarding_issues: true) + end + + context 'and the user is part of the control group' do + before do + stub_experiment_for_user(onboarding_issues: false) + end + + it 'tracks the event with the "created_namespace" action with the "control_group" property' do + expect(Gitlab::Tracking).to receive(:event).with( + 'Growth::Conversion::Experiment::OnboardingIssues', + 'created_namespace', + label: anything, + property: 'control_group' + ) + + create_namespace + end + end + + context 'and the user is part of the experimental group' do + before do + stub_experiment_for_user(onboarding_issues: true) + end + + it 'tracks the event with the "created_namespace" action with the "experimental_group" property' do + expect(Gitlab::Tracking).to receive(:event).with( + 'Growth::Conversion::Experiment::OnboardingIssues', + 'created_namespace', + label: anything, + property: 'experimental_group' + ) + + create_namespace + end + end + end + end end describe 'GET #index' do @@ -862,14 +938,17 @@ describe GroupsController do context 'when the endpoint receives requests above the rate limit' do before do sign_in(admin) - allow(Gitlab::ApplicationRateLimiter).to receive(:throttled?).and_return(true) + + allow(Gitlab::ApplicationRateLimiter) + .to receive(:increment) + .and_return(Gitlab::ApplicationRateLimiter.rate_limits[:group_export][:threshold] + 1) end it 'throttles the endpoint' do post :export, params: { id: group.to_param } - expect(flash[:alert]).to eq('This endpoint has been requested too many times. Try again later.') - expect(response).to have_gitlab_http_status(:found) + expect(response.body).to eq('This endpoint has been requested too many times. Try again later.') + expect(response).to have_gitlab_http_status :too_many_requests end end end @@ -933,14 +1012,17 @@ describe GroupsController do context 'when the endpoint receives requests above the rate limit' do before do sign_in(admin) - allow(Gitlab::ApplicationRateLimiter).to receive(:throttled?).and_return(true) + + allow(Gitlab::ApplicationRateLimiter) + .to receive(:increment) + .and_return(Gitlab::ApplicationRateLimiter.rate_limits[:group_download_export][:threshold] + 1) end it 'throttles the endpoint' do get :download_export, params: { id: group.to_param } - expect(flash[:alert]).to eq('This endpoint has been requested too many times. Try again later.') - expect(response).to have_gitlab_http_status(:found) + expect(response.body).to eq('This endpoint has been requested too many times. Try again later.') + expect(response).to have_gitlab_http_status :too_many_requests end end end diff --git a/spec/controllers/health_check_controller_spec.rb b/spec/controllers/health_check_controller_spec.rb index d1de669ad43..32b72eec0d6 100644 --- a/spec/controllers/health_check_controller_spec.rb +++ b/spec/controllers/health_check_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe HealthCheckController, :request_store do +RSpec.describe HealthCheckController, :request_store do include StubENV let(:xml_response) { Hash.from_xml(response.body)['hash'] } diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index fafbe6bffe1..6c0b3efa53b 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe HelpController do +RSpec.describe HelpController do let(:user) { create(:user) } before do diff --git a/spec/controllers/ide_controller_spec.rb b/spec/controllers/ide_controller_spec.rb index 0462f9520d5..39d92846863 100644 --- a/spec/controllers/ide_controller_spec.rb +++ b/spec/controllers/ide_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe IdeController do +RSpec.describe IdeController do let(:user) { create(:user) } before do diff --git a/spec/controllers/import/bitbucket_controller_spec.rb b/spec/controllers/import/bitbucket_controller_spec.rb index d44edb63635..ec38a635c2d 100644 --- a/spec/controllers/import/bitbucket_controller_spec.rb +++ b/spec/controllers/import/bitbucket_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::BitbucketController do +RSpec.describe Import::BitbucketController do include ImportSpecHelper let(:user) { create(:user) } @@ -56,8 +56,42 @@ describe Import::BitbucketController do describe "GET status" do before do - @repo = double(slug: 'vim', owner: 'asd', full_name: 'asd/vim', "valid?" => true) + @repo = double(name: 'vim', slug: 'vim', owner: 'asd', full_name: 'asd/vim', clone_url: 'http://test.host/demo/url.git', 'valid?' => true) + @invalid_repo = double(name: 'mercurialrepo', slug: 'mercurialrepo', owner: 'asd', full_name: 'asd/mercurialrepo', clone_url: 'http://test.host/demo/mercurialrepo.git', 'valid?' => false) + assign_session_tokens + stub_feature_flags(new_import_ui: false) + end + + it_behaves_like 'import controller with new_import_ui feature flag' do + before do + allow(controller).to receive(:provider_url).and_return('http://demobitbucket.org') + end + + let(:repo) { @repo } + let(:repo_id) { @repo.full_name } + let(:import_source) { @repo.full_name } + let(:provider_name) { 'bitbucket' } + let(:client_repos_field) { :repos } + end + + context 'with new_import_ui feature flag enabled' do + before do + stub_feature_flags(new_import_ui: true) + allow(controller).to receive(:provider_url).and_return('http://demobitbucket.org') + end + + it 'returns invalid repos' do + allow_any_instance_of(Bitbucket::Client).to receive(:repos).and_return([@repo, @invalid_repo]) + + get :status, format: :json + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['incompatible_repos'].length).to eq(1) + expect(json_response.dig("incompatible_repos", 0, "id")).to eq(@invalid_repo.full_name) + expect(json_response['provider_repos'].length).to eq(1) + expect(json_response.dig("provider_repos", 0, "id")).to eq(@repo.full_name) + end end it "assigns variables" do diff --git a/spec/controllers/import/bitbucket_server_controller_spec.rb b/spec/controllers/import/bitbucket_server_controller_spec.rb index 3a347368884..af471b478fa 100644 --- a/spec/controllers/import/bitbucket_server_controller_spec.rb +++ b/spec/controllers/import/bitbucket_server_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::BitbucketServerController do +RSpec.describe Import::BitbucketServerController do let(:user) { create(:user) } let(:project_key) { 'test-project' } let(:repo_slug) { 'some-repo' } @@ -33,7 +33,7 @@ describe Import::BitbucketServerController do let(:project_name) { "my-project_123" } before do - allow(controller).to receive(:bitbucket_client).and_return(client) + allow(controller).to receive(:client).and_return(client) repo = double(name: project_name) allow(client).to receive(:repo).with(project_key, repo_slug).and_return(repo) assign_session_tokens @@ -139,12 +139,39 @@ describe Import::BitbucketServerController do let(:repos) { instance_double(BitbucketServer::Collection) } before do - allow(controller).to receive(:bitbucket_client).and_return(client) + allow(controller).to receive(:client).and_return(client) @repo = double(slug: 'vim', project_key: 'asd', full_name: 'asd/vim', "valid?" => true, project_name: 'asd', browse_url: 'http://test', name: 'vim') - @invalid_repo = double(slug: 'invalid', project_key: 'foobar', full_name: 'asd/foobar', "valid?" => false, browse_url: 'http://bad-repo') + @invalid_repo = double(slug: 'invalid', project_key: 'foobar', full_name: 'asd/foobar', "valid?" => false, browse_url: 'http://bad-repo', name: 'invalid') @created_repo = double(slug: 'created', project_key: 'existing', full_name: 'group/created', "valid?" => true, browse_url: 'http://existing') assign_session_tokens + stub_feature_flags(new_import_ui: false) + end + + context 'with new_import_ui feature flag enabled' do + before do + stub_feature_flags(new_import_ui: true) + end + + it 'returns invalid repos' do + allow(client).to receive(:repos).with(filter: nil, limit: 25, page_offset: 0).and_return([@repo, @invalid_repo]) + + get :status, format: :json + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['incompatible_repos'].length).to eq(1) + expect(json_response.dig("incompatible_repos", 0, "id")).to eq(@invalid_repo.full_name) + expect(json_response['provider_repos'].length).to eq(1) + expect(json_response.dig("provider_repos", 0, "id")).to eq(@repo.full_name) + end + end + + it_behaves_like 'import controller with new_import_ui feature flag' do + let(:repo) { @repo } + let(:repo_id) { @repo.full_name } + let(:import_source) { @repo.browse_url } + let(:provider_name) { 'bitbucket_server' } + let(:client_repos_field) { :repos } end it 'assigns repository categories' do diff --git a/spec/controllers/import/fogbugz_controller_spec.rb b/spec/controllers/import/fogbugz_controller_spec.rb index c833fbfaea5..aabbcb30358 100644 --- a/spec/controllers/import/fogbugz_controller_spec.rb +++ b/spec/controllers/import/fogbugz_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::FogbugzController do +RSpec.describe Import::FogbugzController do include ImportSpecHelper let(:user) { create(:user) } @@ -80,8 +80,17 @@ describe Import::FogbugzController do describe 'GET status' do before do - @repo = OpenStruct.new(name: 'vim') + @repo = OpenStruct.new(id: 'demo', name: 'vim') stub_client(valid?: true) + stub_feature_flags(new_import_ui: false) + end + + it_behaves_like 'import controller with new_import_ui feature flag' do + let(:repo) { @repo } + let(:repo_id) { @repo.id } + let(:import_source) { @repo.name } + let(:provider_name) { 'fogbugz' } + let(:client_repos_field) { :repos } end it 'assigns variables' do diff --git a/spec/controllers/import/gitea_controller_spec.rb b/spec/controllers/import/gitea_controller_spec.rb index 006b423ce5f..9001faef408 100644 --- a/spec/controllers/import/gitea_controller_spec.rb +++ b/spec/controllers/import/gitea_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::GiteaController do +RSpec.describe Import::GiteaController do include ImportSpecHelper let(:provider) { :gitea } diff --git a/spec/controllers/import/github_controller_spec.rb b/spec/controllers/import/github_controller_spec.rb index 40ea0bb3a44..a5a3dc463d3 100644 --- a/spec/controllers/import/github_controller_spec.rb +++ b/spec/controllers/import/github_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::GithubController do +RSpec.describe Import::GithubController do include ImportSpecHelper let(:provider) { :github } diff --git a/spec/controllers/import/gitlab_controller_spec.rb b/spec/controllers/import/gitlab_controller_spec.rb index 96a8eb99d5c..1cd0593f762 100644 --- a/spec/controllers/import/gitlab_controller_spec.rb +++ b/spec/controllers/import/gitlab_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::GitlabController do +RSpec.describe Import::GitlabController do include ImportSpecHelper let(:user) { create(:user) } @@ -34,8 +34,17 @@ describe Import::GitlabController do describe "GET status" do before do - @repo = OpenStruct.new(path: 'vim', path_with_namespace: 'asd/vim') + @repo = OpenStruct.new(id: 1, path: 'vim', path_with_namespace: 'asd/vim', web_url: 'https://gitlab.com/asd/vim') assign_session_token + stub_feature_flags(new_import_ui: false) + end + + it_behaves_like 'import controller with new_import_ui feature flag' do + let(:repo) { @repo } + let(:repo_id) { @repo.id } + let(:import_source) { @repo.path_with_namespace } + let(:provider_name) { 'gitlab' } + let(:client_repos_field) { :projects } end it "assigns variables" do diff --git a/spec/controllers/import/google_code_controller_spec.rb b/spec/controllers/import/google_code_controller_spec.rb index 3773f691ed0..0fda111c029 100644 --- a/spec/controllers/import/google_code_controller_spec.rb +++ b/spec/controllers/import/google_code_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::GoogleCodeController do +RSpec.describe Import::GoogleCodeController do include ImportSpecHelper let(:user) { create(:user) } diff --git a/spec/controllers/import/phabricator_controller_spec.rb b/spec/controllers/import/phabricator_controller_spec.rb index d29a06efbb5..9827a6d077c 100644 --- a/spec/controllers/import/phabricator_controller_spec.rb +++ b/spec/controllers/import/phabricator_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::PhabricatorController do +RSpec.describe Import::PhabricatorController do let(:current_user) { create(:user) } before do diff --git a/spec/controllers/instance_statistics/cohorts_controller_spec.rb b/spec/controllers/instance_statistics/cohorts_controller_spec.rb index 596d3c7abe5..b92fcb2575c 100644 --- a/spec/controllers/instance_statistics/cohorts_controller_spec.rb +++ b/spec/controllers/instance_statistics/cohorts_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe InstanceStatistics::CohortsController do +RSpec.describe InstanceStatistics::CohortsController do let(:user) { create(:user) } before do diff --git a/spec/controllers/instance_statistics/dev_ops_score_controller_spec.rb b/spec/controllers/instance_statistics/dev_ops_score_controller_spec.rb index 5825c6295f6..d729682bef0 100644 --- a/spec/controllers/instance_statistics/dev_ops_score_controller_spec.rb +++ b/spec/controllers/instance_statistics/dev_ops_score_controller_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -describe InstanceStatistics::DevOpsScoreController do +RSpec.describe InstanceStatistics::DevOpsScoreController do it_behaves_like 'instance statistics availability' end diff --git a/spec/controllers/invites_controller_spec.rb b/spec/controllers/invites_controller_spec.rb index 9daaa258aa2..f2821bb67e8 100644 --- a/spec/controllers/invites_controller_spec.rb +++ b/spec/controllers/invites_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe InvitesController do +RSpec.describe InvitesController do let(:token) { '123456' } let(:user) { create(:user) } let(:member) { create(:project_member, invite_token: token, invite_email: 'test@abc.com', user: user) } diff --git a/spec/controllers/ldap/omniauth_callbacks_controller_spec.rb b/spec/controllers/ldap/omniauth_callbacks_controller_spec.rb index 0242a91ac60..2de824bbf3c 100644 --- a/spec/controllers/ldap/omniauth_callbacks_controller_spec.rb +++ b/spec/controllers/ldap/omniauth_callbacks_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Ldap::OmniauthCallbacksController do +RSpec.describe Ldap::OmniauthCallbacksController do include_context 'Ldap::OmniauthCallbacksController' it 'allows sign in' do diff --git a/spec/controllers/metrics_controller_spec.rb b/spec/controllers/metrics_controller_spec.rb index 75509cc509f..f350d7378dc 100644 --- a/spec/controllers/metrics_controller_spec.rb +++ b/spec/controllers/metrics_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe MetricsController, :request_store do +RSpec.describe MetricsController, :request_store do include StubENV let(:metrics_multiproc_dir) { @metrics_multiproc_dir } diff --git a/spec/controllers/notification_settings_controller_spec.rb b/spec/controllers/notification_settings_controller_spec.rb index f3b608aee0c..c4d67df15f7 100644 --- a/spec/controllers/notification_settings_controller_spec.rb +++ b/spec/controllers/notification_settings_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe NotificationSettingsController do +RSpec.describe NotificationSettingsController do let(:project) { create(:project) } let(:group) { create(:group, :internal) } let(:user) { create(:user) } diff --git a/spec/controllers/oauth/applications_controller_spec.rb b/spec/controllers/oauth/applications_controller_spec.rb index 09f8ad4332d..f20204b6718 100644 --- a/spec/controllers/oauth/applications_controller_spec.rb +++ b/spec/controllers/oauth/applications_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Oauth::ApplicationsController do +RSpec.describe Oauth::ApplicationsController do let(:user) { create(:user) } let(:application) { create(:oauth_application, owner: user) } diff --git a/spec/controllers/oauth/authorizations_controller_spec.rb b/spec/controllers/oauth/authorizations_controller_spec.rb index f975502ca4e..89b74675d28 100644 --- a/spec/controllers/oauth/authorizations_controller_spec.rb +++ b/spec/controllers/oauth/authorizations_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Oauth::AuthorizationsController do +RSpec.describe Oauth::AuthorizationsController do let!(:application) { create(:oauth_application, scopes: 'api read_user', redirect_uri: 'http://example.com') } let(:params) do { diff --git a/spec/controllers/oauth/authorized_applications_controller_spec.rb b/spec/controllers/oauth/authorized_applications_controller_spec.rb index 32be6a3ddb7..15b2969a859 100644 --- a/spec/controllers/oauth/authorized_applications_controller_spec.rb +++ b/spec/controllers/oauth/authorized_applications_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Oauth::AuthorizedApplicationsController do +RSpec.describe Oauth::AuthorizedApplicationsController do let(:user) { create(:user) } let(:guest) { create(:user) } let(:application) { create(:oauth_application, owner: guest) } diff --git a/spec/controllers/omniauth_callbacks_controller_spec.rb b/spec/controllers/omniauth_callbacks_controller_spec.rb index 0d8a6827afe..0b99f28f79b 100644 --- a/spec/controllers/omniauth_callbacks_controller_spec.rb +++ b/spec/controllers/omniauth_callbacks_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe OmniauthCallbacksController, type: :controller do +RSpec.describe OmniauthCallbacksController, type: :controller do include LoginHelpers describe 'omniauth' do @@ -212,7 +212,7 @@ describe OmniauthCallbacksController, type: :controller do end it 'allows linking the disabled provider' do - user.identities.destroy_all # rubocop: disable DestroyAll + user.identities.destroy_all # rubocop: disable Cop/DestroyAll sign_in(user) expect { post provider }.to change { user.reload.identities.count }.by(1) diff --git a/spec/controllers/passwords_controller_spec.rb b/spec/controllers/passwords_controller_spec.rb index 3ec8e347659..ba2c0c0455d 100644 --- a/spec/controllers/passwords_controller_spec.rb +++ b/spec/controllers/passwords_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe PasswordsController do +RSpec.describe PasswordsController do describe '#check_password_authentication_available' do before do @request.env["devise.mapping"] = Devise.mappings[:user] diff --git a/spec/controllers/profiles/accounts_controller_spec.rb b/spec/controllers/profiles/accounts_controller_spec.rb index 518ea4e5c48..52a7a1609a1 100644 --- a/spec/controllers/profiles/accounts_controller_spec.rb +++ b/spec/controllers/profiles/accounts_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Profiles::AccountsController do +RSpec.describe Profiles::AccountsController do describe 'DELETE unlink' do let(:user) { create(:omniauth_user) } diff --git a/spec/controllers/profiles/avatars_controller_spec.rb b/spec/controllers/profiles/avatars_controller_spec.rb index 1a64cb72265..d120d9ce559 100644 --- a/spec/controllers/profiles/avatars_controller_spec.rb +++ b/spec/controllers/profiles/avatars_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Profiles::AvatarsController do +RSpec.describe Profiles::AvatarsController do let(:user) { create(:user, avatar: fixture_file_upload("spec/fixtures/dk.png")) } before do diff --git a/spec/controllers/profiles/emails_controller_spec.rb b/spec/controllers/profiles/emails_controller_spec.rb index ffec43fea2c..246f8a6cd76 100644 --- a/spec/controllers/profiles/emails_controller_spec.rb +++ b/spec/controllers/profiles/emails_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Profiles::EmailsController do +RSpec.describe Profiles::EmailsController do let(:user) { create(:user) } before do diff --git a/spec/controllers/profiles/keys_controller_spec.rb b/spec/controllers/profiles/keys_controller_spec.rb index 8582ecbb06d..258ed62262a 100644 --- a/spec/controllers/profiles/keys_controller_spec.rb +++ b/spec/controllers/profiles/keys_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Profiles::KeysController do +RSpec.describe Profiles::KeysController do let(:user) { create(:user) } describe 'POST #create' do diff --git a/spec/controllers/profiles/notifications_controller_spec.rb b/spec/controllers/profiles/notifications_controller_spec.rb index 343f29ef687..40b4c8f0371 100644 --- a/spec/controllers/profiles/notifications_controller_spec.rb +++ b/spec/controllers/profiles/notifications_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Profiles::NotificationsController do +RSpec.describe Profiles::NotificationsController do let(:user) do create(:user) do |user| user.emails.create(email: 'original@example.com', confirmed_at: Time.current) diff --git a/spec/controllers/profiles/personal_access_tokens_controller_spec.rb b/spec/controllers/profiles/personal_access_tokens_controller_spec.rb index b467ecc4af9..1fdd1200028 100644 --- a/spec/controllers/profiles/personal_access_tokens_controller_spec.rb +++ b/spec/controllers/profiles/personal_access_tokens_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Profiles::PersonalAccessTokensController do +RSpec.describe Profiles::PersonalAccessTokensController do let(:user) { create(:user) } let(:token_attributes) { attributes_for(:personal_access_token) } diff --git a/spec/controllers/profiles/preferences_controller_spec.rb b/spec/controllers/profiles/preferences_controller_spec.rb index 98a9c3eaec6..4a68475c37f 100644 --- a/spec/controllers/profiles/preferences_controller_spec.rb +++ b/spec/controllers/profiles/preferences_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Profiles::PreferencesController do +RSpec.describe Profiles::PreferencesController do let(:user) { create(:user) } before do diff --git a/spec/controllers/profiles/two_factor_auths_controller_spec.rb b/spec/controllers/profiles/two_factor_auths_controller_spec.rb index b02af0096a5..f645081219a 100644 --- a/spec/controllers/profiles/two_factor_auths_controller_spec.rb +++ b/spec/controllers/profiles/two_factor_auths_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Profiles::TwoFactorAuthsController do +RSpec.describe Profiles::TwoFactorAuthsController do before do # `user` should be defined within the action-specific describe blocks sign_in(user) diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb index d6d2c73d049..e08c92da87f 100644 --- a/spec/controllers/profiles_controller_spec.rb +++ b/spec/controllers/profiles_controller_spec.rb @@ -2,7 +2,7 @@ require('spec_helper') -describe ProfilesController, :request_store do +RSpec.describe ProfilesController, :request_store do let(:user) { create(:user) } describe 'POST update' do diff --git a/spec/controllers/projects/alert_management_controller_spec.rb b/spec/controllers/projects/alert_management_controller_spec.rb index b84376db33d..6a1952f949b 100644 --- a/spec/controllers/projects/alert_management_controller_spec.rb +++ b/spec/controllers/projects/alert_management_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::AlertManagementController do +RSpec.describe Projects::AlertManagementController do let_it_be(:project) { create(:project) } let_it_be(:role) { :developer } let_it_be(:user) { create(:user) } diff --git a/spec/controllers/projects/alerting/notifications_controller_spec.rb b/spec/controllers/projects/alerting/notifications_controller_spec.rb index 9d26c2278b1..33fd73c762a 100644 --- a/spec/controllers/projects/alerting/notifications_controller_spec.rb +++ b/spec/controllers/projects/alerting/notifications_controller_spec.rb @@ -2,90 +2,101 @@ require 'spec_helper' -describe Projects::Alerting::NotificationsController do +RSpec.describe Projects::Alerting::NotificationsController do let_it_be(:project) { create(:project) } let_it_be(:environment) { create(:environment, project: project) } describe 'POST #create' do - let(:service_response) { ServiceResponse.success } - let(:notify_service) { instance_double(Projects::Alerting::NotifyService, execute: service_response) } - around do |example| ForgeryProtection.with_forgery_protection { example.run } end - before do - allow(Projects::Alerting::NotifyService).to receive(:new).and_return(notify_service) - end + shared_examples 'process alert payload' do |notify_service_class| + let(:service_response) { ServiceResponse.success } + let(:notify_service) { instance_double(notify_service_class, execute: service_response) } - def make_request(body = {}) - post :create, params: project_params, body: body.to_json, as: :json - end + before do + allow(notify_service_class).to receive(:new).and_return(notify_service) + end - context 'when notification service succeeds' do - let(:payload) do - { - title: 'Alert title', - hosts: 'https://gitlab.com' - } + def make_request + post :create, params: project_params, body: payload.to_json, as: :json end - let(:permitted_params) { ActionController::Parameters.new(payload).permit! } + context 'when notification service succeeds' do + let(:permitted_params) { ActionController::Parameters.new(payload).permit! } - it 'responds with ok' do - make_request + it 'responds with ok' do + make_request - expect(response).to have_gitlab_http_status(:ok) - end + expect(response).to have_gitlab_http_status(:ok) + end - it 'does not pass excluded parameters to the notify service' do - make_request(payload) + it 'does not pass excluded parameters to the notify service' do + make_request - expect(Projects::Alerting::NotifyService) - .to have_received(:new) - .with(project, nil, permitted_params) + expect(notify_service_class) + .to have_received(:new) + .with(project, nil, permitted_params) + end end - end - context 'when notification service fails' do - let(:service_response) { ServiceResponse.error(message: 'Unauthorized', http_status: :unauthorized) } + context 'when notification service fails' do + let(:service_response) { ServiceResponse.error(message: 'Unauthorized', http_status: :unauthorized) } - it 'responds with the service response' do - make_request + it 'responds with the service response' do + make_request - expect(response).to have_gitlab_http_status(:unauthorized) + expect(response).to have_gitlab_http_status(:unauthorized) + end end - end - context 'bearer token' do - context 'when set' do - it 'extracts bearer token' do - request.headers['HTTP_AUTHORIZATION'] = 'Bearer some token' + context 'bearer token' do + context 'when set' do + it 'extracts bearer token' do + request.headers['HTTP_AUTHORIZATION'] = 'Bearer some token' - expect(notify_service).to receive(:execute).with('some token') + expect(notify_service).to receive(:execute).with('some token') - make_request - end + make_request + end - it 'pass nil if cannot extract a non-bearer token' do - request.headers['HTTP_AUTHORIZATION'] = 'some token' + it 'pass nil if cannot extract a non-bearer token' do + request.headers['HTTP_AUTHORIZATION'] = 'some token' - expect(notify_service).to receive(:execute).with(nil) + expect(notify_service).to receive(:execute).with(nil) - make_request + make_request + end end - end - context 'when missing' do - it 'passes nil' do - expect(notify_service).to receive(:execute).with(nil) + context 'when missing' do + it 'passes nil' do + expect(notify_service).to receive(:execute).with(nil) - make_request + make_request + end end end end + + context 'generic alert payload' do + it_behaves_like 'process alert payload', Projects::Alerting::NotifyService do + let(:payload) { { title: 'Alert title' } } + end + end + + context 'Prometheus alert payload' do + include PrometheusHelpers + + it_behaves_like 'process alert payload', Projects::Prometheus::Alerts::NotifyService do + let(:payload) { prometheus_alert_payload } + end + end end + private + def project_params(opts = {}) opts.reverse_merge(namespace_id: project.namespace, project_id: project) end diff --git a/spec/controllers/projects/artifacts_controller_spec.rb b/spec/controllers/projects/artifacts_controller_spec.rb index 4c815a5b40c..69ab9873b90 100644 --- a/spec/controllers/projects/artifacts_controller_spec.rb +++ b/spec/controllers/projects/artifacts_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::ArtifactsController do +RSpec.describe Projects::ArtifactsController do include RepoHelpers let(:user) { project.owner } @@ -371,10 +371,9 @@ describe Projects::ArtifactsController do end context 'when the artifact is zip' do - let!(:artifact) { create(:ci_job_artifact, :lsif, job: job, file_path: Rails.root.join("spec/fixtures/#{file_name}")) } + let!(:artifact) { create(:ci_job_artifact, :lsif, job: job) } let(:path) { 'lsif/main.go.json' } - let(:file_name) { 'lsif.json.zip' } - let(:archive_matcher) { file_name } + let(:archive_matcher) { 'lsif.json.zip' } let(:query_params) { super().merge(file_type: :lsif, path: path) } it_behaves_like 'a valid file' do diff --git a/spec/controllers/projects/autocomplete_sources_controller_spec.rb b/spec/controllers/projects/autocomplete_sources_controller_spec.rb index d35192b2ccb..865b31a28d7 100644 --- a/spec/controllers/projects/autocomplete_sources_controller_spec.rb +++ b/spec/controllers/projects/autocomplete_sources_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::AutocompleteSourcesController do +RSpec.describe Projects::AutocompleteSourcesController do let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, namespace: group) } let_it_be(:issue) { create(:issue, project: project) } diff --git a/spec/controllers/projects/avatars_controller_spec.rb b/spec/controllers/projects/avatars_controller_spec.rb index 54c2397625f..16e9c845307 100644 --- a/spec/controllers/projects/avatars_controller_spec.rb +++ b/spec/controllers/projects/avatars_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::AvatarsController do +RSpec.describe Projects::AvatarsController do let_it_be(:project) { create(:project, :repository) } before do diff --git a/spec/controllers/projects/badges_controller_spec.rb b/spec/controllers/projects/badges_controller_spec.rb index 4ae29ba7f54..7e7a630921f 100644 --- a/spec/controllers/projects/badges_controller_spec.rb +++ b/spec/controllers/projects/badges_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::BadgesController do +RSpec.describe Projects::BadgesController do let(:project) { pipeline.project } let!(:pipeline) { create(:ci_empty_pipeline) } let(:user) { create(:user) } @@ -54,7 +54,7 @@ describe Projects::BadgesController do context 'when style param is set to `flat`' do it 'renders the `flat` badge layout' do - get_badge(badge_type, 'flat') + get_badge(badge_type, style: 'flat') expect(response).to render_template('projects/badges/badge') end @@ -62,7 +62,7 @@ describe Projects::BadgesController do context 'when style param is set to an invalid type' do it 'renders the `flat` (default) badge layout' do - get_badge(badge_type, 'xxx') + get_badge(badge_type, style: 'xxx') expect(response).to render_template('projects/badges/badge') end @@ -70,7 +70,7 @@ describe Projects::BadgesController do context 'when style param is set to `flat-square`' do it 'renders the `flat-square` badge layout' do - get_badge(badge_type, 'flat-square') + get_badge(badge_type, style: 'flat-square') expect(response).to render_template('projects/badges/badge_flat-square') end @@ -102,12 +102,37 @@ describe Projects::BadgesController do end it 'defaults to project permissions' do - get_badge(:coverage) + get_badge(badge_type) expect(response).to have_gitlab_http_status(:not_found) end end end + + context 'customization' do + render_views + + before do + project.add_maintainer(user) + sign_in(user) + end + + context 'when key_text param is used' do + it 'sets custom key text' do + get_badge(badge_type, key_text: 'custom key text') + + expect(response.body).to include('custom key text') + end + end + + context 'when key_width param is used' do + it 'sets custom key width' do + get_badge(badge_type, key_width: '123') + + expect(response.body).to include('123') + end + end + end end describe '#pipeline' do @@ -118,13 +143,12 @@ describe Projects::BadgesController do it_behaves_like 'a badge resource', :coverage end - def get_badge(badge, style = nil) + def get_badge(badge, args = {}) params = { namespace_id: project.namespace.to_param, project_id: project, - ref: pipeline.ref, - style: style - } + ref: pipeline.ref + }.merge(args.slice(:style, :key_text, :key_width)) get badge, params: params, format: :svg end diff --git a/spec/controllers/projects/blame_controller_spec.rb b/spec/controllers/projects/blame_controller_spec.rb index ac8394e3cd4..bf475f6135a 100644 --- a/spec/controllers/projects/blame_controller_spec.rb +++ b/spec/controllers/projects/blame_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::BlameController do +RSpec.describe Projects::BlameController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } diff --git a/spec/controllers/projects/blob_controller_spec.rb b/spec/controllers/projects/blob_controller_spec.rb index ad04c6e61e8..9fee97f938c 100644 --- a/spec/controllers/projects/blob_controller_spec.rb +++ b/spec/controllers/projects/blob_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::BlobController do +RSpec.describe Projects::BlobController do include ProjectForksHelper let(:project) { create(:project, :public, :repository) } @@ -378,6 +378,22 @@ describe Projects::BlobController do expect(response).to redirect_to(after_delete_path) end + + context 'when a validation failure occurs' do + let(:failure_path) { project_blob_path(project, default_params[:id]) } + + render_views + + it 'redirects to a valid page' do + expect_next_instance_of(Files::DeleteService) do |instance| + expect(instance).to receive(:validate!).and_raise(Commits::CreateService::ValidationError, "validation error") + end + + delete :destroy, params: default_params + + expect(response).to redirect_to(failure_path) + end + end end context 'if deleted file is the last one in a subdirectory' do diff --git a/spec/controllers/projects/boards_controller_spec.rb b/spec/controllers/projects/boards_controller_spec.rb index 6634801939b..dad932f9cdf 100644 --- a/spec/controllers/projects/boards_controller_spec.rb +++ b/spec/controllers/projects/boards_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::BoardsController do +RSpec.describe Projects::BoardsController do let(:project) { create(:project) } let(:user) { create(:user) } diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index 174d8904481..625fc5bddda 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -2,14 +2,13 @@ require 'spec_helper' -describe Projects::BranchesController do +RSpec.describe Projects::BranchesController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:developer) { create(:user) } before do - project.add_maintainer(user) - project.add_developer(user) + project.add_developer(developer) allow(project).to receive(:branches).and_return(['master', 'foo/bar/baz']) allow(project).to receive(:tags).and_return(['v1.0.0', 'v2.0.0']) @@ -21,7 +20,7 @@ describe Projects::BranchesController do context "on creation of a new branch" do before do - sign_in(user) + sign_in(developer) post :create, params: { @@ -80,7 +79,7 @@ describe Projects::BranchesController do let(:issue) { create(:issue, project: project) } before do - sign_in(user) + sign_in(developer) end it 'redirects' do @@ -97,7 +96,7 @@ describe Projects::BranchesController do end it 'posts a system note' do - expect(SystemNoteService).to receive(:new_issue_branch).with(issue, project, user, "1-feature-branch", branch_project: project) + expect(SystemNoteService).to receive(:new_issue_branch).with(issue, project, developer, "1-feature-branch", branch_project: project) post :create, params: { @@ -136,14 +135,14 @@ describe Projects::BranchesController do context 'user can update issue' do before do - confidential_issue_project.add_reporter(user) + confidential_issue_project.add_reporter(developer) end context 'issue is under the specified project' do let(:issue) { create(:issue, project: confidential_issue_project) } it 'posts a system note' do - expect(SystemNoteService).to receive(:new_issue_branch).with(issue, confidential_issue_project, user, "1-feature-branch", branch_project: project) + expect(SystemNoteService).to receive(:new_issue_branch).with(issue, confidential_issue_project, developer, "1-feature-branch", branch_project: project) create_branch_with_confidential_issue_project end @@ -264,7 +263,7 @@ describe Projects::BranchesController do describe 'POST create with JSON format' do before do - sign_in(user) + sign_in(developer) end context 'with valid params' do @@ -305,7 +304,7 @@ describe Projects::BranchesController do render_views before do - sign_in(user) + sign_in(developer) end it 'returns 303' do @@ -325,7 +324,7 @@ describe Projects::BranchesController do render_views before do - sign_in(user) + sign_in(developer) post :destroy, format: format, @@ -436,7 +435,7 @@ describe Projects::BranchesController do context 'when user is allowed to push' do before do - sign_in(user) + sign_in(developer) end it 'redirects to branches' do @@ -454,7 +453,7 @@ describe Projects::BranchesController do context 'when user is not allowed to push' do before do - sign_in(developer) + sign_in(user) end it 'responds with status 404' do @@ -469,7 +468,7 @@ describe Projects::BranchesController do render_views before do - sign_in(user) + sign_in(developer) end context 'when rendering a JSON format' do @@ -487,6 +486,82 @@ describe Projects::BranchesController do end end + context 'when a branch has multiple pipelines' do + it 'chooses the latest to determine status' do + sha = project.repository.create_file(developer, generate(:branch), 'content', message: 'message', branch_name: 'master') + create(:ci_pipeline, + project: project, + user: developer, + ref: "master", + sha: sha, + status: :running, + created_at: 6.months.ago) + create(:ci_pipeline, + project: project, + user: developer, + ref: "master", + sha: sha, + status: :success, + created_at: 2.months.ago) + + get :index, + format: :html, + params: { + namespace_id: project.namespace, + project_id: project, + state: 'all' + } + + expect(controller.instance_variable_get(:@branch_pipeline_statuses)["master"].group).to eq("success") + end + end + + context 'when multiple branches exist' do + it 'all relevant commit statuses are received' do + master_sha = project.repository.create_file(developer, generate(:branch), 'content', message: 'message', branch_name: 'master') + create(:ci_pipeline, + project: project, + user: developer, + ref: "master", + sha: master_sha, + status: :running, + created_at: 6.months.ago) + test_sha = project.repository.create_file(developer, generate(:branch), 'content', message: 'message', branch_name: 'test') + create(:ci_pipeline, + project: project, + user: developer, + ref: "test", + sha: test_sha, + status: :success, + created_at: 2.months.ago) + + get :index, + format: :html, + params: { + namespace_id: project.namespace, + project_id: project, + state: 'all' + } + + expect(controller.instance_variable_get(:@branch_pipeline_statuses)["master"].group).to eq("running") + expect(controller.instance_variable_get(:@branch_pipeline_statuses)["test"].group).to eq("success") + end + end + + context 'when a branch contains no pipelines' do + it 'no commit statuses are received' do + get :index, + format: :html, + params: { + namespace_id: project.namespace, + project_id: project, + state: 'all' + } + + expect(controller.instance_variable_get(:@branch_pipeline_statuses)).to be_blank + end + end + # We need :request_store because Gitaly only counts the queries whenever # `RequestStore.active?` in GitalyClient.enforce_gitaly_request_limits # And the main goal of this test is making sure TooManyInvocationsError @@ -564,7 +639,7 @@ describe Projects::BranchesController do describe 'GET diverging_commit_counts' do before do - sign_in(user) + sign_in(developer) end it 'returns the commit counts behind and ahead of default branch' do diff --git a/spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb b/spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb index ac31045678f..252ad6ec9c4 100644 --- a/spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb +++ b/spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb @@ -2,34 +2,27 @@ require 'spec_helper' -describe Projects::Ci::DailyBuildGroupReportResultsController do +RSpec.describe Projects::Ci::DailyBuildGroupReportResultsController do describe 'GET index' do let(:project) { create(:project, :public, :repository) } let(:ref_path) { 'refs/heads/master' } let(:param_type) { 'coverage' } let(:start_date) { '2019-12-10' } let(:end_date) { '2020-03-09' } - - def create_daily_coverage(group_name, coverage, date) - create( - :ci_daily_build_group_report_result, - project: project, - ref_path: ref_path, - group_name: group_name, - data: { 'coverage' => coverage }, - date: date - ) - end - - def csv_response - CSV.parse(response.body) - end + let(:allowed_to_read) { true } + let(:user) { create(:user) } before do create_daily_coverage('rspec', 79.0, '2020-03-09') + create_daily_coverage('rspec', 77.0, '2020-03-08') create_daily_coverage('karma', 81.0, '2019-12-10') - create_daily_coverage('rspec', 67.0, '2019-12-09') - create_daily_coverage('karma', 71.0, '2019-12-09') + create_daily_coverage('minitest', 67.0, '2019-12-09') + create_daily_coverage('mocha', 71.0, '2019-12-09') + + sign_in(user) + + allow(Ability).to receive(:allowed?).and_call_original + allow(Ability).to receive(:allowed?).with(user, :read_build_report_results, project).and_return(allowed_to_read) get :index, params: { namespace_id: project.namespace, @@ -38,43 +31,126 @@ describe Projects::Ci::DailyBuildGroupReportResultsController do param_type: param_type, start_date: start_date, end_date: end_date, - format: :csv + format: format } end - it 'serves the results in CSV' do - expect(response).to have_gitlab_http_status(:ok) - expect(response.headers['Content-Type']).to eq('text/csv; charset=utf-8') + shared_examples_for 'validating param_type' do + context 'when given param_type is invalid' do + let(:param_type) { 'something_else' } - expect(csv_response).to eq([ - %w[date group_name coverage], - ['2020-03-09', 'rspec', '79.0'], - ['2019-12-10', 'karma', '81.0'] - ]) + it 'responds with 422 error' do + expect(response).to have_gitlab_http_status(:unprocessable_entity) + end + end end - context 'when given date range spans more than 90 days' do - let(:start_date) { '2019-12-09' } - let(:end_date) { '2020-03-09' } + shared_examples_for 'ensuring policy' do + context 'when user is not allowed to read build report results' do + let(:allowed_to_read) { false } + + it 'responds with 404 error' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + end - it 'limits the result to 90 days from the given start_date' do + context 'when format is CSV' do + let(:format) { :csv } + + it 'serves the results in CSV' do expect(response).to have_gitlab_http_status(:ok) expect(response.headers['Content-Type']).to eq('text/csv; charset=utf-8') expect(csv_response).to eq([ %w[date group_name coverage], ['2020-03-09', 'rspec', '79.0'], + ['2020-03-08', 'rspec', '77.0'], ['2019-12-10', 'karma', '81.0'] ]) end + + context 'when given date range spans more than 90 days' do + let(:start_date) { '2019-12-09' } + let(:end_date) { '2020-03-09' } + + it 'limits the result to 90 days from the given start_date' do + expect(csv_response).to eq([ + %w[date group_name coverage], + ['2020-03-09', 'rspec', '79.0'], + ['2020-03-08', 'rspec', '77.0'], + ['2019-12-10', 'karma', '81.0'] + ]) + end + end + + it_behaves_like 'validating param_type' + it_behaves_like 'ensuring policy' end - context 'when given param_type is invalid' do - let(:param_type) { 'something_else' } + context 'when format is JSON' do + let(:format) { :json } + + it 'serves the results in JSON' do + expect(response).to have_gitlab_http_status(:ok) - it 'responds with 422 error' do - expect(response).to have_gitlab_http_status(:unprocessable_entity) + expect(json_response).to eq([ + { + 'group_name' => 'rspec', + 'data' => [ + { 'date' => '2020-03-09', 'coverage' => 79.0 }, + { 'date' => '2020-03-08', 'coverage' => 77.0 } + ] + }, + { + 'group_name' => 'karma', + 'data' => [ + { 'date' => '2019-12-10', 'coverage' => 81.0 } + ] + } + ]) end + + context 'when given date range spans more than 90 days' do + let(:start_date) { '2019-12-09' } + let(:end_date) { '2020-03-09' } + + it 'limits the result to 90 days from the given start_date' do + expect(json_response).to eq([ + { + 'group_name' => 'rspec', + 'data' => [ + { 'date' => '2020-03-09', 'coverage' => 79.0 }, + { 'date' => '2020-03-08', 'coverage' => 77.0 } + ] + }, + { + 'group_name' => 'karma', + 'data' => [ + { 'date' => '2019-12-10', 'coverage' => 81.0 } + ] + } + ]) + end + end + + it_behaves_like 'validating param_type' + it_behaves_like 'ensuring policy' end end + + def create_daily_coverage(group_name, coverage, date) + create( + :ci_daily_build_group_report_result, + project: project, + ref_path: ref_path, + group_name: group_name, + data: { 'coverage' => coverage }, + date: date + ) + end + + def csv_response + CSV.parse(response.body) + end end diff --git a/spec/controllers/projects/ci/lints_controller_spec.rb b/spec/controllers/projects/ci/lints_controller_spec.rb index f45b1d7ddd8..eb92385fc83 100644 --- a/spec/controllers/projects/ci/lints_controller_spec.rb +++ b/spec/controllers/projects/ci/lints_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Ci::LintsController do +RSpec.describe Projects::Ci::LintsController do include StubRequests let(:project) { create(:project, :repository) } diff --git a/spec/controllers/projects/clusters/applications_controller_spec.rb b/spec/controllers/projects/clusters/applications_controller_spec.rb index 6de3593be28..b50814b4790 100644 --- a/spec/controllers/projects/clusters/applications_controller_spec.rb +++ b/spec/controllers/projects/clusters/applications_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Clusters::ApplicationsController do +RSpec.describe Projects::Clusters::ApplicationsController do include AccessMatchersForController def current_application diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb index 698a3773d59..5645e25b741 100644 --- a/spec/controllers/projects/clusters_controller_spec.rb +++ b/spec/controllers/projects/clusters_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::ClustersController do +RSpec.describe Projects::ClustersController do include AccessMatchersForController include GoogleApi::CloudPlatformHelpers include KubernetesHelpers @@ -41,6 +41,13 @@ describe Projects::ClustersController do expect(response).to match_response_schema('cluster_list') end + it 'sets the polling interval header for json requests' do + go(format: :json) + + expect(response).to have_gitlab_http_status(:ok) + expect(response.headers['Poll-Interval']).to eq("10000") + end + context 'when page is specified' do let(:last_page) { project.clusters.page.total_pages } let(:total_count) { project.clusters.page.total_count } diff --git a/spec/controllers/projects/commit_controller_spec.rb b/spec/controllers/projects/commit_controller_spec.rb index c8ddd181d10..706bf787b2d 100644 --- a/spec/controllers/projects/commit_controller_spec.rb +++ b/spec/controllers/projects/commit_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::CommitController do +RSpec.describe Projects::CommitController do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } diff --git a/spec/controllers/projects/commits_controller_spec.rb b/spec/controllers/projects/commits_controller_spec.rb index 1977e92e42b..557002acbc0 100644 --- a/spec/controllers/projects/commits_controller_spec.rb +++ b/spec/controllers/projects/commits_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::CommitsController do +RSpec.describe Projects::CommitsController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } diff --git a/spec/controllers/projects/compare_controller_spec.rb b/spec/controllers/projects/compare_controller_spec.rb index d1a4a9a0058..6aa4bfe235b 100644 --- a/spec/controllers/projects/compare_controller_spec.rb +++ b/spec/controllers/projects/compare_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::CompareController do +RSpec.describe Projects::CompareController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } diff --git a/spec/controllers/projects/cycle_analytics/events_controller_spec.rb b/spec/controllers/projects/cycle_analytics/events_controller_spec.rb index 942e095d669..408ce51d34b 100644 --- a/spec/controllers/projects/cycle_analytics/events_controller_spec.rb +++ b/spec/controllers/projects/cycle_analytics/events_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::CycleAnalytics::EventsController do +RSpec.describe Projects::CycleAnalytics::EventsController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } diff --git a/spec/controllers/projects/cycle_analytics_controller_spec.rb b/spec/controllers/projects/cycle_analytics_controller_spec.rb index 65eee7b8ead..8feb964cdde 100644 --- a/spec/controllers/projects/cycle_analytics_controller_spec.rb +++ b/spec/controllers/projects/cycle_analytics_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::CycleAnalyticsController do +RSpec.describe Projects::CycleAnalyticsController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } diff --git a/spec/controllers/projects/deploy_keys_controller_spec.rb b/spec/controllers/projects/deploy_keys_controller_spec.rb index 9d41e2f59cb..821f7fca73d 100644 --- a/spec/controllers/projects/deploy_keys_controller_spec.rb +++ b/spec/controllers/projects/deploy_keys_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::DeployKeysController do +RSpec.describe Projects::DeployKeysController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:admin) { create(:admin) } diff --git a/spec/controllers/projects/deployments_controller_spec.rb b/spec/controllers/projects/deployments_controller_spec.rb index 37dcfa78772..85dd86d91e9 100644 --- a/spec/controllers/projects/deployments_controller_spec.rb +++ b/spec/controllers/projects/deployments_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::DeploymentsController do +RSpec.describe Projects::DeploymentsController do include ApiHelpers let(:user) { create(:user) } diff --git a/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb b/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb index 30d2b79a92f..f664604ac15 100644 --- a/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb +++ b/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::DesignManagement::Designs::RawImagesController do +RSpec.describe Projects::DesignManagement::Designs::RawImagesController do include DesignManagementTestHelpers let_it_be(:project) { create(:project, :private) } diff --git a/spec/controllers/projects/design_management/designs/resized_image_controller_spec.rb b/spec/controllers/projects/design_management/designs/resized_image_controller_spec.rb index 6bfec1b314e..96ecbaf55b6 100644 --- a/spec/controllers/projects/design_management/designs/resized_image_controller_spec.rb +++ b/spec/controllers/projects/design_management/designs/resized_image_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::DesignManagement::Designs::ResizedImageController do +RSpec.describe Projects::DesignManagement::Designs::ResizedImageController do include DesignManagementTestHelpers let_it_be(:project) { create(:project, :private) } diff --git a/spec/controllers/projects/discussions_controller_spec.rb b/spec/controllers/projects/discussions_controller_spec.rb index b2e4a3b7b0d..f2efd40afdb 100644 --- a/spec/controllers/projects/discussions_controller_spec.rb +++ b/spec/controllers/projects/discussions_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::DiscussionsController do +RSpec.describe Projects::DiscussionsController do let(:user) { create(:user) } let(:merge_request) { create(:merge_request) } let(:project) { merge_request.source_project } diff --git a/spec/controllers/projects/environments/prometheus_api_controller_spec.rb b/spec/controllers/projects/environments/prometheus_api_controller_spec.rb index fb8da52930c..17952aa0683 100644 --- a/spec/controllers/projects/environments/prometheus_api_controller_spec.rb +++ b/spec/controllers/projects/environments/prometheus_api_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Environments::PrometheusApiController do +RSpec.describe Projects::Environments::PrometheusApiController do let_it_be(:project) { create(:project) } let_it_be(:environment) { create(:environment, project: project) } let_it_be(:user) { create(:user) } diff --git a/spec/controllers/projects/environments/sample_metrics_controller_spec.rb b/spec/controllers/projects/environments/sample_metrics_controller_spec.rb index 19b07a2ccc4..14e3ded76f2 100644 --- a/spec/controllers/projects/environments/sample_metrics_controller_spec.rb +++ b/spec/controllers/projects/environments/sample_metrics_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Environments::SampleMetricsController do +RSpec.describe Projects::Environments::SampleMetricsController do include StubENV let_it_be(:project) { create(:project) } diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb index 56fff2771ec..cca4b597f4c 100644 --- a/spec/controllers/projects/environments_controller_spec.rb +++ b/spec/controllers/projects/environments_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::EnvironmentsController do +RSpec.describe Projects::EnvironmentsController do include MetricsDashboardHelpers let_it_be(:project) { create(:project) } @@ -354,6 +354,19 @@ describe Projects::EnvironmentsController do expect(response).to redirect_to(environment_metrics_path(environment)) end + context 'with anonymous user and public dashboard visibility' do + let(:project) { create(:project, :public) } + let(:user) { create(:user) } + + it 'redirects successfully' do + project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED) + + get :metrics_redirect, params: { namespace_id: project.namespace, project_id: project } + + expect(response).to redirect_to(environment_metrics_path(environment)) + end + end + context 'when there are no environments' do let(:environment) { } @@ -422,6 +435,19 @@ describe Projects::EnvironmentsController do get :metrics, params: environment_params end end + + context 'with anonymous user and public dashboard visibility' do + let(:project) { create(:project, :public) } + let(:user) { create(:user) } + + it 'returns success' do + project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED) + + get :metrics, params: environment_params + + expect(response).to have_gitlab_http_status(:ok) + end + end end describe 'GET #additional_metrics' do @@ -497,6 +523,26 @@ describe Projects::EnvironmentsController do get :metrics, params: environment_params end end + + context 'with anonymous user and public dashboard visibility' do + let(:project) { create(:project, :public) } + let(:user) { create(:user) } + + it 'does not fail' do + allow(environment) + .to receive(:additional_metrics) + .and_return({ + success: true, + data: {}, + last_update: 42 + }) + project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED) + + additional_metrics(window_params) + + expect(response).to have_gitlab_http_status(:ok) + end + end end describe 'GET #metrics_dashboard' do @@ -673,6 +719,17 @@ describe Projects::EnvironmentsController do it_behaves_like 'dashboard can be specified' it_behaves_like 'dashboard can be embedded' + context 'with anonymous user and public dashboard visibility' do + let(:project) { create(:project, :public) } + let(:user) { create(:user) } + + before do + project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED) + end + + it_behaves_like 'the default dashboard' + end + context 'permissions' do before do allow(controller).to receive(:can?).and_return true diff --git a/spec/controllers/projects/error_tracking/projects_controller_spec.rb b/spec/controllers/projects/error_tracking/projects_controller_spec.rb index 1737528b597..67947d1c9d9 100644 --- a/spec/controllers/projects/error_tracking/projects_controller_spec.rb +++ b/spec/controllers/projects/error_tracking/projects_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::ErrorTracking::ProjectsController do +RSpec.describe Projects::ErrorTracking::ProjectsController do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } diff --git a/spec/controllers/projects/error_tracking/stack_traces_controller_spec.rb b/spec/controllers/projects/error_tracking/stack_traces_controller_spec.rb index 27d49147e99..7c080504c31 100644 --- a/spec/controllers/projects/error_tracking/stack_traces_controller_spec.rb +++ b/spec/controllers/projects/error_tracking/stack_traces_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::ErrorTracking::StackTracesController do +RSpec.describe Projects::ErrorTracking::StackTracesController do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } diff --git a/spec/controllers/projects/error_tracking_controller_spec.rb b/spec/controllers/projects/error_tracking_controller_spec.rb index 6be979418ad..5ea885e4fd6 100644 --- a/spec/controllers/projects/error_tracking_controller_spec.rb +++ b/spec/controllers/projects/error_tracking_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::ErrorTrackingController do +RSpec.describe Projects::ErrorTrackingController do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } diff --git a/spec/controllers/projects/find_file_controller_spec.rb b/spec/controllers/projects/find_file_controller_spec.rb index 4d8933f3aaf..a6c71cff74b 100644 --- a/spec/controllers/projects/find_file_controller_spec.rb +++ b/spec/controllers/projects/find_file_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::FindFileController do +RSpec.describe Projects::FindFileController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } diff --git a/spec/controllers/projects/forks_controller_spec.rb b/spec/controllers/projects/forks_controller_spec.rb index e362790cd3c..4c0fd7b8954 100644 --- a/spec/controllers/projects/forks_controller_spec.rb +++ b/spec/controllers/projects/forks_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::ForksController do +RSpec.describe Projects::ForksController do let(:user) { create(:user) } let(:project) { create(:project, :public, :repository) } let(:forked_project) { Projects::ForkService.new(project, user, name: 'Some name').execute } diff --git a/spec/controllers/projects/grafana_api_controller_spec.rb b/spec/controllers/projects/grafana_api_controller_spec.rb index 8502bd1ab0a..baee9705127 100644 --- a/spec/controllers/projects/grafana_api_controller_spec.rb +++ b/spec/controllers/projects/grafana_api_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::GrafanaApiController do +RSpec.describe Projects::GrafanaApiController do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } diff --git a/spec/controllers/projects/graphs_controller_spec.rb b/spec/controllers/projects/graphs_controller_spec.rb index e589815c45d..12cef6bea09 100644 --- a/spec/controllers/projects/graphs_controller_spec.rb +++ b/spec/controllers/projects/graphs_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::GraphsController do +RSpec.describe Projects::GraphsController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } @@ -42,23 +42,42 @@ describe Projects::GraphsController do expect(response).to render_template(:charts) end - it 'sets the daily coverage options' do - Timecop.freeze do + context 'when anonymous users can read build report results' do + it 'sets the daily coverage options' do + Timecop.freeze do + get(:charts, params: { namespace_id: project.namespace.path, project_id: project.path, id: 'master' }) + + expect(assigns[:daily_coverage_options]).to eq( + base_params: { + start_date: Date.current - 90.days, + end_date: Date.current, + ref_path: project.repository.expand_ref('master'), + param_type: 'coverage' + }, + download_path: namespace_project_ci_daily_build_group_report_results_path( + namespace_id: project.namespace, + project_id: project, + format: :csv + ), + graph_api_path: namespace_project_ci_daily_build_group_report_results_path( + namespace_id: project.namespace, + project_id: project, + format: :json + ) + ) + end + end + end + + context 'when anonymous users cannot read build report results' do + before do + project.update_column(:public_builds, false) + get(:charts, params: { namespace_id: project.namespace.path, project_id: project.path, id: 'master' }) + end - expect(assigns[:daily_coverage_options]).to eq( - base_params: { - start_date: Time.current.to_date - 90.days, - end_date: Time.current.to_date, - ref_path: project.repository.expand_ref('master'), - param_type: 'coverage' - }, - download_path: namespace_project_ci_daily_build_group_report_results_path( - namespace_id: project.namespace, - project_id: project, - format: :csv - ) - ) + it 'does not set daily coverage options' do + expect(assigns[:daily_coverage_options]).to be_nil end end end diff --git a/spec/controllers/projects/group_links_controller_spec.rb b/spec/controllers/projects/group_links_controller_spec.rb index 28999257957..762ef795f6e 100644 --- a/spec/controllers/projects/group_links_controller_spec.rb +++ b/spec/controllers/projects/group_links_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::GroupLinksController do +RSpec.describe Projects::GroupLinksController do let(:group) { create(:group, :private) } let(:group2) { create(:group, :private) } let(:project) { create(:project, :private, group: group2) } diff --git a/spec/controllers/projects/hooks_controller_spec.rb b/spec/controllers/projects/hooks_controller_spec.rb index e97f602d9ab..440e6b2a74c 100644 --- a/spec/controllers/projects/hooks_controller_spec.rb +++ b/spec/controllers/projects/hooks_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::HooksController do +RSpec.describe Projects::HooksController do let(:project) { create(:project) } let(:user) { create(:user) } diff --git a/spec/controllers/projects/import/jira_controller_spec.rb b/spec/controllers/projects/import/jira_controller_spec.rb index d1b0a086576..b82735a56b3 100644 --- a/spec/controllers/projects/import/jira_controller_spec.rb +++ b/spec/controllers/projects/import/jira_controller_spec.rb @@ -2,230 +2,101 @@ require 'spec_helper' -describe Projects::Import::JiraController do +RSpec.describe Projects::Import::JiraController do include JiraServiceHelper let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:jira_project_key) { 'Test' } - context 'with anonymous user' do - before do - stub_feature_flags(jira_issue_import: true) - end + def ensure_correct_config + sign_in(user) + project.add_maintainer(user) + stub_feature_flags(jira_issue_import: true) + stub_jira_service_test + end - context 'get show' do - it 'redirects to issues page' do - get :show, params: { namespace_id: project.namespace, project_id: project } + shared_examples 'redirect with error' do |error| + it 'redirects to project issues path' do + subject - expect(response).to redirect_to(new_user_session_path) - end + expect(response).to redirect_to(project_issues_path(project)) end - context 'post import' do - it 'redirects to issues page' do - post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: jira_project_key } + it 'renders a correct error' do + subject - expect(response).to redirect_to(new_user_session_path) - end + expect(flash[:notice]).to eq(error) end end - context 'with logged in user' do - before do - sign_in(user) - project.add_maintainer(user) - end + shared_examples 'template with no message' do + it 'does not set any message' do + subject - context 'when feature flag not enabled' do - before do - stub_feature_flags(jira_issue_import: false) - end + expect(flash).to be_empty + end - context 'get show' do - it 'redirects to issues page' do - get :show, params: { namespace_id: project.namespace, project_id: project } + it 'renders show template' do + subject - expect(response).to redirect_to(project_issues_path(project)) - end - end + expect(response).to render_template(template) + end + end - context 'post import' do - it 'redirects to issues page' do - post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: jira_project_key } + shared_examples 'users without permissions' do + context 'with anonymous user' do + it 'redirects to new user page' do + subject - expect(response).to redirect_to(project_issues_path(project)) - end + expect(response).to redirect_to(new_user_session_path) end end - context 'when feature flag enabled' do + context 'when loged user is a developer' do before do - stub_feature_flags(jira_issue_import: true) - stub_feature_flags(jira_issue_import_vue: false) + create(:jira_service, project: project) stub_jira_service_test - end - - context 'when Jira service is enabled for the project' do - let_it_be(:jira_service) { create(:jira_service, project: project) } - - context 'when user is developer' do - let_it_be(:dev) { create(:user) } - - before do - sign_in(dev) - project.add_developer(dev) - end - - context 'get show' do - before do - get :show, params: { namespace_id: project.namespace.to_param, project_id: project } - end - - it 'does not query Jira service' do - expect(project).not_to receive(:jira_service) - end - - it 'renders show template' do - expect(response).to render_template(:show) - expect(assigns(:jira_projects)).not_to be_present - end - end - - context 'post import' do - it 'returns 404' do - post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: jira_project_key } - expect(response).to have_gitlab_http_status(:not_found) - end - end - end - - context 'when issues disabled' do - let_it_be(:disabled_issues_project) { create(:project, :public, :issues_disabled) } - - context 'get show' do - it 'returs 404' do - get :show, params: { namespace_id: project.namespace.to_param, project_id: disabled_issues_project } - - expect(response).to have_gitlab_http_status(:not_found) - end - end - - context 'post import' do - it 'returs 404' do - post :import, params: { namespace_id: disabled_issues_project.namespace, project_id: disabled_issues_project, jira_project_key: jira_project_key } - - expect(response).to have_gitlab_http_status(:not_found) - end - end - end - - context 'when running Jira import first time' do - context 'get show' do - before do - allow(JIRA::Resource::Project).to receive(:all).and_return(jira_projects) - - expect(project.jira_imports).to be_empty - - get :show, params: { namespace_id: project.namespace.to_param, project_id: project } - end - - context 'when no projects have been retrieved from Jira' do - let(:jira_projects) { [] } - - it 'render an error message' do - expect(flash[:alert]).to eq('No projects have been returned from Jira. Please check your Jira configuration.') - expect(response).to render_template(:show) - end - end - - context 'when projects retrieved from Jira' do - let(:jira_projects) { [double(name: 'FOO project', key: 'FOO')] } - - it 'renders show template' do - expect(response).to render_template(:show) - end - end - end + sign_in(user) + project.add_developer(user) + end - context 'post import' do - context 'when Jira project key is empty' do - it 'redirects back to show with an error' do - post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: '' } + it_behaves_like 'redirect with error', 'You do not have permissions to run the import.' + end + end - expect(response).to redirect_to(project_import_jira_path(project)) - expect(flash[:alert]).to eq('No Jira project key has been provided.') - end - end + describe 'GET #show' do + let(:template) { 'show' } - context 'when everything is ok' do - it 'creates import state' do - expect(project.latest_jira_import).to be_nil + subject { get :show, params: { namespace_id: project.namespace, project_id: project } } - post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: jira_project_key } + it_behaves_like 'users without permissions' - project.reload + context 'jira service configuration' do + before do + sign_in(user) + project.add_maintainer(user) + stub_feature_flags(jira_issue_import: true) + end - jira_import = project.latest_jira_import - expect(project.import_type).to eq 'jira' - expect(jira_import.status).to eq 'scheduled' - expect(jira_import.jira_project_key).to eq jira_project_key - expect(response).to redirect_to(project_import_jira_path(project)) - end - end - end + context 'when Jira service is not enabled for the project' do + it 'does not query Jira service' do + expect(project).not_to receive(:jira_service) end - context 'when import state is scheduled' do - let_it_be(:jira_import_state) { create(:jira_import_state, :scheduled, project: project) } - - context 'get show' do - it 'renders import status' do - get :show, params: { namespace_id: project.namespace.to_param, project_id: project } - - jira_import = project.latest_jira_import - expect(jira_import.status).to eq 'scheduled' - expect(flash.now[:notice]).to eq 'Import scheduled' - end - end + it_behaves_like 'template with no message' + end - context 'post import' do - it 'uses the existing import data' do - post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: 'New Project' } + context 'when Jira service is not configured correctly for the project' do + let_it_be(:jira_service) { create(:jira_service, project: project) } - expect(flash[:notice]).to eq('Jira import is already running.') - expect(response).to redirect_to(project_import_jira_path(project)) - end - end + before do + WebMock.stub_request(:get, 'https://jira.example.com/rest/api/2/serverInfo') + .to_raise(JIRA::HTTPError.new(double(message: 'Some failure.'))) end - context 'when Jira import ran before' do - let_it_be(:jira_import_state) { create(:jira_import_state, :finished, project: project, jira_project_key: jira_project_key) } - - context 'get show' do - it 'renders import status' do - allow(JIRA::Resource::Project).to receive(:all).and_return([]) - get :show, params: { namespace_id: project.namespace.to_param, project_id: project } - - expect(project.latest_jira_import.status).to eq 'finished' - expect(flash.now[:notice]).to eq 'Import finished' - end - end - - context 'post import' do - it 'uses the existing import data' do - post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: 'New Project' } - - project.reload - expect(project.latest_jira_import.status).to eq 'scheduled' - expect(project.jira_imports.size).to eq 2 - expect(project.jira_imports.first.jira_project_key).to eq jira_project_key - expect(project.jira_imports.last.jira_project_key).to eq 'New Project' - expect(response).to redirect_to(project_import_jira_path(project)) - end - end - end + it_behaves_like 'template with no message' end end end diff --git a/spec/controllers/projects/imports_controller_spec.rb b/spec/controllers/projects/imports_controller_spec.rb index bdc81efe3bc..29cfd1c352e 100644 --- a/spec/controllers/projects/imports_controller_spec.rb +++ b/spec/controllers/projects/imports_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::ImportsController do +RSpec.describe Projects::ImportsController do let(:user) { create(:user) } let(:project) { create(:project) } diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index 96f11f11dc4..bcd1a53bd47 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::IssuesController do +RSpec.describe Projects::IssuesController do include ProjectForksHelper include_context 'includes Spam constants' @@ -332,8 +332,7 @@ describe Projects::IssuesController do end before do - allow(controller).to receive(:find_routable!) - .with(Project, project.full_path, any_args).and_return(project) + allow(controller).to receive(:find_routable!).and_return(project) allow(project).to receive(:default_branch).and_return(master_branch) allow_next_instance_of(Issues::RelatedBranchesService) do |service| allow(service).to receive(:execute).and_return(related_branches) @@ -536,7 +535,7 @@ describe Projects::IssuesController do before do stub_application_setting(recaptcha_enabled: true) expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service| - expect(verdict_service).to receive(:execute).and_return(REQUIRE_RECAPTCHA) + expect(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW) end end @@ -851,7 +850,7 @@ describe Projects::IssuesController do context 'when recaptcha is not verified' do before do expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service| - expect(verdict_service).to receive(:execute).and_return(REQUIRE_RECAPTCHA) + expect(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW) end end @@ -1103,7 +1102,7 @@ describe Projects::IssuesController do context 'when captcha is not verified' do before do expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service| - expect(verdict_service).to receive(:execute).and_return(REQUIRE_RECAPTCHA) + expect(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW) end end diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb index ef1253edda5..44dcb0caab2 100644 --- a/spec/controllers/projects/jobs_controller_spec.rb +++ b/spec/controllers/projects/jobs_controller_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe Projects::JobsController, :clean_gitlab_redis_shared_state do +RSpec.describe Projects::JobsController, :clean_gitlab_redis_shared_state do include ApiHelpers include HttpIOHelpers @@ -1225,4 +1225,198 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do get :terminal_websocket_authorize, params: params.merge(extra_params) end end + + describe 'GET #proxy_websocket_authorize' do + let_it_be(:owner) { create(:owner) } + let_it_be(:admin) { create(:admin) } + let_it_be(:maintainer) { create(:user) } + let_it_be(:developer) { create(:user) } + let_it_be(:reporter) { create(:user) } + let_it_be(:guest) { create(:user) } + let_it_be(:project) { create(:project, :private, :repository, namespace: owner.namespace) } + let(:user) { maintainer } + let(:pipeline) { create(:ci_pipeline, project: project, source: :webide, config_source: :webide_source, user: user) } + let(:job) { create(:ci_build, :running, :with_runner_session, pipeline: pipeline, user: user) } + let(:extra_params) { { id: job.id } } + let(:path) { :proxy_websocket_authorize } + let(:render_method) { :channel_websocket } + let(:expected_data) do + { + 'Channel' => { + 'Subprotocols' => ["terminal.gitlab.com"], + 'Url' => 'wss://localhost/proxy/build/default_port/', + 'Header' => { + 'Authorization' => [nil] + }, + 'MaxSessionTime' => nil, + 'CAPem' => nil + } + }.to_json + end + + before do + stub_feature_flags(build_service_proxy: true) + allow(job).to receive(:has_terminal?).and_return(true) + + project.add_maintainer(maintainer) + project.add_developer(developer) + project.add_reporter(reporter) + project.add_guest(guest) + + sign_in(user) + end + + context 'access rights' do + before do + allow(Gitlab::Workhorse).to receive(:verify_api_request!).and_return(nil) + + make_request + end + + context 'with admin' do + let(:user) { admin } + + context 'when admin mode is enabled', :enable_admin_mode do + it 'returns 200' do + expect(response).to have_gitlab_http_status(:ok) + end + end + + context 'when admin mode is disabled' do + it 'returns 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + context 'with owner' do + let(:user) { owner } + + it 'returns 200' do + expect(response).to have_gitlab_http_status(:ok) + end + end + + context 'with maintainer' do + let(:user) { maintainer } + + it 'returns 200' do + expect(response).to have_gitlab_http_status(:ok) + end + end + + context 'with developer' do + let(:user) { developer } + + it 'returns 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'with reporter' do + let(:user) { reporter } + + it 'returns 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'with guest' do + let(:user) { guest } + + it 'returns 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'with non member' do + let(:user) { create(:user) } + + it 'returns 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + context 'when pipeline is not from a webide source' do + context 'with admin' do + let(:user) { admin } + let(:pipeline) { create(:ci_pipeline, project: project, source: :chat, user: user) } + + before do + allow(Gitlab::Workhorse).to receive(:verify_api_request!).and_return(nil) + make_request + end + + it 'returns 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + context 'when workhorse signature is valid' do + before do + allow(Gitlab::Workhorse).to receive(:verify_api_request!).and_return(nil) + end + + context 'and the id is valid' do + it 'returns the proxy data for the service running in the job' do + make_request + + expect(response).to have_gitlab_http_status(:ok) + expect(response.headers["Content-Type"]).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) + expect(response.body).to eq(expected_data) + end + end + + context 'and the id is invalid' do + let(:extra_params) { { id: non_existing_record_id } } + + it 'returns 404' do + make_request + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + context 'with invalid workhorse signature' do + it 'aborts with an exception' do + allow(Gitlab::Workhorse).to receive(:verify_api_request!).and_raise(JWT::DecodeError) + + expect { make_request }.to raise_error(JWT::DecodeError) + end + end + + context 'when feature flag :build_service_proxy is disabled' do + let(:user) { admin } + + it 'returns 404' do + allow(Gitlab::Workhorse).to receive(:verify_api_request!).and_return(nil) + stub_feature_flags(build_service_proxy: false) + + make_request + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + it 'converts the url scheme into wss' do + allow(Gitlab::Workhorse).to receive(:verify_api_request!).and_return(nil) + + expect(job.runner_session_url).to start_with('https://') + expect(Gitlab::Workhorse).to receive(:channel_websocket).with(a_hash_including(url: "wss://localhost/proxy/build/default_port/")) + + make_request + end + + def make_request + params = { + namespace_id: project.namespace.to_param, + project_id: project + } + + get path, params: params.merge(extra_params) + end + end end diff --git a/spec/controllers/projects/labels_controller_spec.rb b/spec/controllers/projects/labels_controller_spec.rb index c6098f5934d..f213d104747 100644 --- a/spec/controllers/projects/labels_controller_spec.rb +++ b/spec/controllers/projects/labels_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::LabelsController do +RSpec.describe Projects::LabelsController do let(:group) { create(:group) } let(:project) { create(:project, namespace: group) } let(:user) { create(:user) } diff --git a/spec/controllers/projects/logs_controller_spec.rb b/spec/controllers/projects/logs_controller_spec.rb index e86a42b03c8..1eb5a6fcc12 100644 --- a/spec/controllers/projects/logs_controller_spec.rb +++ b/spec/controllers/projects/logs_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::LogsController do +RSpec.describe Projects::LogsController do include KubernetesHelpers let_it_be(:user) { create(:user) } diff --git a/spec/controllers/projects/mattermosts_controller_spec.rb b/spec/controllers/projects/mattermosts_controller_spec.rb index 693176d0cfc..001f2564698 100644 --- a/spec/controllers/projects/mattermosts_controller_spec.rb +++ b/spec/controllers/projects/mattermosts_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::MattermostsController do +RSpec.describe Projects::MattermostsController do let!(:project) { create(:project) } let!(:user) { create(:user) } diff --git a/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb b/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb index 8e4ac64f7b0..5f636bd4340 100644 --- a/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::MergeRequests::ConflictsController do +RSpec.describe Projects::MergeRequests::ConflictsController do let(:project) { create(:project, :repository) } let(:user) { project.owner } let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } diff --git a/spec/controllers/projects/merge_requests/content_controller_spec.rb b/spec/controllers/projects/merge_requests/content_controller_spec.rb index 72eedc837a4..7fb20b4666a 100644 --- a/spec/controllers/projects/merge_requests/content_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/content_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::MergeRequests::ContentController do +RSpec.describe Projects::MergeRequests::ContentController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:merge_request) { create(:merge_request, target_project: project, source_project: project) } diff --git a/spec/controllers/projects/merge_requests/creations_controller_spec.rb b/spec/controllers/projects/merge_requests/creations_controller_spec.rb index db25ad62019..091a44130a1 100644 --- a/spec/controllers/projects/merge_requests/creations_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/creations_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::MergeRequests::CreationsController do +RSpec.describe Projects::MergeRequests::CreationsController do let(:project) { create(:project, :repository) } let(:user) { project.owner } let(:fork_project) { create(:forked_project_with_submodules) } diff --git a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb index 3d9193e3e33..02b4c2d1da9 100644 --- a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::MergeRequests::DiffsController do +RSpec.describe Projects::MergeRequests::DiffsController do include ProjectForksHelper shared_examples '404 for unexistent diffable' do diff --git a/spec/controllers/projects/merge_requests/drafts_controller_spec.rb b/spec/controllers/projects/merge_requests/drafts_controller_spec.rb new file mode 100644 index 00000000000..7d74e872d29 --- /dev/null +++ b/spec/controllers/projects/merge_requests/drafts_controller_spec.rb @@ -0,0 +1,455 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Projects::MergeRequests::DraftsController do + include RepoHelpers + + let(:project) { create(:project, :repository) } + let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } + let(:user) { project.owner } + let(:user2) { create(:user) } + + let(:params) do + { + namespace_id: project.namespace.to_param, + project_id: project.to_param, + merge_request_id: merge_request.iid + } + end + + before do + sign_in(user) + stub_licensed_features(multiple_merge_request_assignees: true) + stub_commonmark_sourcepos_disabled + end + + describe 'GET #index' do + let!(:draft_note) { create(:draft_note, merge_request: merge_request, author: user) } + + it 'list merge request draft notes for current user' do + get :index, params: params + + expect(json_response.first['merge_request_id']).to eq(merge_request.id) + expect(json_response.first['author']['id']).to eq(user.id) + expect(json_response.first['note_html']).not_to be_empty + end + end + + describe 'POST #create' do + def create_draft_note(draft_overrides: {}, overrides: {}) + post_params = params.merge({ + draft_note: { + note: 'This is a unpublished comment' + }.merge(draft_overrides) + }.merge(overrides)) + + post :create, params: post_params + end + + context 'without permissions' do + let(:project) { create(:project, :private) } + + before do + sign_in(user2) + end + + it 'does not allow draft note creation' do + expect { create_draft_note }.to change { DraftNote.count }.by(0) + expect(response).to have_gitlab_http_status(:not_found) + end + end + + it 'creates a draft note' do + expect { create_draft_note }.to change { DraftNote.count }.by(1) + end + + it 'creates draft note with position' do + diff_refs = project.commit(sample_commit.id).try(:diff_refs) + + position = Gitlab::Diff::Position.new( + old_path: "files/ruby/popen.rb", + new_path: "files/ruby/popen.rb", + old_line: nil, + new_line: 14, + diff_refs: diff_refs + ) + + create_draft_note(draft_overrides: { position: position.to_json }) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['position']).to be_present + expect(json_response['file_hash']).to be_present + expect(json_response['file_identifier_hash']).to be_present + expect(json_response['line_code']).to match(/\w+_\d+_\d+/) + expect(json_response['note_html']).to eq('<p dir="auto">This is a unpublished comment</p>') + end + + it 'creates a draft note with quick actions' do + create_draft_note(draft_overrides: { note: "#{user2.to_reference}\n/assign #{user.to_reference}" }) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['note_html']).to match(/#{user2.to_reference}/) + expect(json_response['references']['commands']).to match(/Assigns/) + expect(json_response['references']['users']).to include(user2.username) + end + + context 'in a thread' do + let(:discussion) { create(:discussion_note_on_merge_request, noteable: merge_request, project: project).discussion } + + it 'creates draft note as a reply' do + expect do + create_draft_note(overrides: { in_reply_to_discussion_id: discussion.reply_id }) + end.to change { DraftNote.count }.by(1) + + draft_note = DraftNote.last + + expect(draft_note).to be_valid + expect(draft_note.discussion_id).to eq(discussion.reply_id) + end + + it 'creates a draft note that will resolve a thread' do + expect do + create_draft_note( + overrides: { in_reply_to_discussion_id: discussion.reply_id }, + draft_overrides: { resolve_discussion: true } + ) + end.to change { DraftNote.count }.by(1) + + draft_note = DraftNote.last + + expect(draft_note).to be_valid + expect(draft_note.discussion_id).to eq(discussion.reply_id) + expect(draft_note.resolve_discussion).to eq(true) + end + + it 'cannot create more than one draft note per thread' do + expect do + create_draft_note( + overrides: { in_reply_to_discussion_id: discussion.reply_id }, + draft_overrides: { resolve_discussion: true } + ) + end.to change { DraftNote.count }.by(1) + + expect do + create_draft_note( + overrides: { in_reply_to_discussion_id: discussion.reply_id }, + draft_overrides: { resolve_discussion: true, note: 'A note' } + ) + end.to change { DraftNote.count }.by(0) + end + end + + context 'commit_id is present' do + let(:commit) { project.commit(sample_commit.id) } + + let(:position) do + Gitlab::Diff::Position.new( + old_path: "files/ruby/popen.rb", + new_path: "files/ruby/popen.rb", + old_line: nil, + new_line: 14, + diff_refs: commit.diff_refs + ) + end + + before do + create_draft_note(draft_overrides: { commit_id: commit_id, position: position.to_json }) + end + + context 'value is a commit sha' do + let(:commit_id) { commit.id } + + it 'creates the draft note with commit ID' do + expect(DraftNote.last.commit_id).to eq(commit_id) + end + end + + context 'value is "undefined"' do + let(:commit_id) { 'undefined' } + + it 'creates the draft note with nil commit ID' do + expect(DraftNote.last.commit_id).to be_nil + end + end + end + end + + describe 'PUT #update' do + let(:draft) { create(:draft_note, merge_request: merge_request, author: user) } + + def update_draft_note(overrides = {}) + put_params = params.merge({ + id: draft.id, + draft_note: { + note: 'This is an updated unpublished comment' + }.merge(overrides) + }) + + put :update, params: put_params + end + + context 'without permissions' do + before do + sign_in(user2) + project.add_developer(user2) + end + + it 'does not allow editing draft note belonging to someone else' do + update_draft_note + + expect(response).to have_gitlab_http_status(:not_found) + expect(draft.reload.note).not_to eq('This is an updated unpublished comment') + end + end + + it 'updates the draft' do + expect(draft.note).not_to be_empty + + expect { update_draft_note }.not_to change { DraftNote.count } + + draft.reload + + expect(draft.note).to eq('This is an updated unpublished comment') + expect(json_response['note_html']).not_to be_empty + end + end + + describe 'POST #publish' do + context 'without permissions' do + shared_examples_for 'action that does not allow publishing draft note' do + it 'does not allow publishing draft note' do + expect { action } + .to not_change { Note.count } + .and not_change { DraftNote.count } + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + before do + sign_in(user2) + end + + context 'when note belongs to someone else' do + before do + project.add_developer(user2) + end + + it_behaves_like 'action that does not allow publishing draft note' do + let!(:draft) { create(:draft_note, merge_request: merge_request, author: user) } + let(:action) { post :publish, params: params.merge(id: draft.id) } + end + end + + context 'when merge request discussion is locked' do + let(:project) { create(:project, :public, :merge_requests_public, :repository) } + + before do + create(:draft_note, merge_request: merge_request, author: user2) + merge_request.update!(discussion_locked: true) + end + + it_behaves_like 'action that does not allow publishing draft note' do + let(:action) { post :publish, params: params } + end + end + end + + context 'when PublishService errors' do + it 'returns message and 500 response' do + create(:draft_note, merge_request: merge_request, author: user) + error_message = "Something went wrong" + + expect_next_instance_of(DraftNotes::PublishService) do |service| + allow(service).to receive(:execute).and_return({ message: error_message, status: :error }) + end + + post :publish, params: params + + expect(response).to have_gitlab_http_status(:error) + expect(json_response["message"]).to include(error_message) + end + end + + it 'publishes draft notes with position' do + diff_refs = project.commit(sample_commit.id).try(:diff_refs) + + position = Gitlab::Diff::Position.new( + old_path: "files/ruby/popen.rb", + new_path: "files/ruby/popen.rb", + old_line: nil, + new_line: 14, + diff_refs: diff_refs + ) + + draft = create(:draft_note_on_text_diff, merge_request: merge_request, author: user, position: position) + + expect { post :publish, params: params }.to change { Note.count }.by(1) + .and change { DraftNote.count }.by(-1) + + note = merge_request.notes.reload.last + + expect(note.note).to eq(draft.note) + expect(note.position).to eq(draft.position) + end + + it 'does nothing if there are no draft notes' do + expect { post :publish, params: params }.to change { Note.count }.by(0).and change { DraftNote.count }.by(0) + end + + it 'publishes a draft note with quick actions and applies them' do + project.add_developer(user2) + create(:draft_note, merge_request: merge_request, author: user, + note: "/assign #{user2.to_reference}") + + expect(merge_request.assignees).to be_empty + + expect { post :publish, params: params }.to change { Note.count }.by(1) + .and change { DraftNote.count }.by(-1) + + expect(response).to have_gitlab_http_status(:ok) + expect(merge_request.reload.assignee_ids).to match_array([user2.id]) + expect(Note.last.system?).to be true + end + + it 'publishes all draft notes for an MR' do + draft_params = { merge_request: merge_request, author: user } + + drafts = create_list(:draft_note, 4, draft_params) + + note = create(:discussion_note_on_merge_request, noteable: merge_request, project: project) + draft_reply = create(:draft_note, draft_params.merge(discussion_id: note.discussion_id)) + + diff_note = create(:diff_note_on_merge_request, noteable: merge_request, project: project) + diff_draft_reply = create(:draft_note, draft_params.merge(discussion_id: diff_note.discussion_id)) + + expect { post :publish, params: params }.to change { Note.count }.by(6) + .and change { DraftNote.count }.by(-6) + + expect(response).to have_gitlab_http_status(:ok) + + notes = merge_request.notes.reload + + expect(notes.pluck(:note)).to include(*drafts.map(&:note)) + expect(note.discussion.notes.last.note).to eq(draft_reply.note) + expect(diff_note.discussion.notes.last.note).to eq(diff_draft_reply.note) + end + + it 'can publish just a single draft note' do + draft_params = { merge_request: merge_request, author: user } + + drafts = create_list(:draft_note, 4, draft_params) + + expect { post :publish, params: params.merge(id: drafts.first.id) }.to change { Note.count }.by(1) + .and change { DraftNote.count }.by(-1) + end + + context 'when publishing drafts in a thread' do + let(:note) { create(:discussion_note_on_merge_request, noteable: merge_request, project: project) } + + def create_reply(discussion_id, resolves: false) + create(:draft_note, + merge_request: merge_request, + author: user, + discussion_id: discussion_id, + resolve_discussion: resolves + ) + end + + it 'resolves a thread if the draft note resolves it' do + draft_reply = create_reply(note.discussion_id, resolves: true) + + post :publish, params: params + + discussion = note.discussion + + expect(discussion.notes.last.note).to eq(draft_reply.note) + expect(discussion.resolved?).to eq(true) + expect(discussion.resolved_by.id).to eq(user.id) + end + + it 'unresolves a thread if the draft note unresolves it' do + note.discussion.resolve!(user) + expect(note.discussion.resolved?).to eq(true) + + draft_reply = create_reply(note.discussion_id, resolves: false) + + post :publish, params: params + + discussion = note.discussion + + expect(discussion.notes.last.note).to eq(draft_reply.note) + expect(discussion.resolved?).to eq(false) + end + end + end + + describe 'DELETE #destroy' do + let(:draft) { create(:draft_note, merge_request: merge_request, author: user) } + + def create_draft + create(:draft_note, merge_request: merge_request, author: user) + end + + context 'without permissions' do + before do + sign_in(user2) + project.add_developer(user2) + end + + it 'does not allow destroying a draft note belonging to someone else' do + draft = create(:draft_note, merge_request: merge_request, author: user) + + expect { post :destroy, params: params.merge(id: draft.id) } + .not_to change { DraftNote.count } + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + it 'destroys the draft note when ID is given' do + draft = create_draft + + expect { delete :destroy, params: params.merge(id: draft.id) }.to change { DraftNote.count }.by(-1) + expect(response).to have_gitlab_http_status(:ok) + end + + context 'without permissions' do + before do + sign_in(user2) + end + + it 'does not allow editing draft note belonging to someone else' do + draft = create_draft + + expect { delete :destroy, params: params.merge(id: draft.id) }.to change { DraftNote.count }.by(0) + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + describe 'DELETE #discard' do + it 'deletes all DraftNotes belonging to a user in a Merge Request' do + create_list(:draft_note, 6, merge_request: merge_request, author: user) + + expect { delete :discard, params: params }.to change { DraftNote.count }.by(-6) + expect(response).to have_gitlab_http_status(:ok) + end + + context 'without permissions' do + before do + sign_in(user2) + project.add_developer(user2) + end + + it 'does not destroys a draft note belonging to someone else' do + create(:draft_note, merge_request: merge_request, author: user) + + expect { post :discard, params: params } + .not_to change { DraftNote.count } + + expect(response).to have_gitlab_http_status(:ok) + end + end + end +end diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index 7d9e42fcc2d..382593fd7cb 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::MergeRequestsController do +RSpec.describe Projects::MergeRequestsController do include ProjectForksHelper include Gitlab::Routing @@ -1183,15 +1183,19 @@ describe Projects::MergeRequestsController do subject expect(response).to have_gitlab_http_status(:ok) - expect(json_response).to match( - a_hash_including( - 'tfplan.json' => hash_including( - 'create' => 0, - 'delete' => 0, - 'update' => 1 + + pipeline.builds.each do |build| + expect(json_response).to match( + a_hash_including( + build.id.to_s => hash_including( + 'create' => 0, + 'delete' => 0, + 'update' => 1, + 'job_name' => build.options.dig(:artifacts, :name).to_s + ) ) ) - ) + end end end @@ -1409,20 +1413,6 @@ describe Projects::MergeRequestsController do end end - context 'when feature flag is disabled' do - let(:accessibility_comparison) { { status: :parsed, data: { summary: 1 } } } - - before do - stub_feature_flags(accessibility_report_view: false) - end - - it 'returns 204 HTTP status' do - subject - - expect(response).to have_gitlab_http_status(:no_content) - end - end - context 'when pipeline has jobs with accessibility reports' do before do allow_any_instance_of(MergeRequest) diff --git a/spec/controllers/projects/milestones_controller_spec.rb b/spec/controllers/projects/milestones_controller_spec.rb index ee61ef73b45..0c7391c1b9c 100644 --- a/spec/controllers/projects/milestones_controller_spec.rb +++ b/spec/controllers/projects/milestones_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::MilestonesController do +RSpec.describe Projects::MilestonesController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:milestone) { create(:milestone, project: project) } @@ -145,7 +145,7 @@ describe Projects::MilestonesController do delete :destroy, params: { namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid }, format: :js expect(response).to be_successful - expect(Event.recent.first.action).to eq(Event::DESTROYED) + expect(Event.recent.first).to be_destroyed_action expect { Milestone.find(milestone.id) }.to raise_exception(ActiveRecord::RecordNotFound) issue.reload diff --git a/spec/controllers/projects/mirrors_controller_spec.rb b/spec/controllers/projects/mirrors_controller_spec.rb index 8cd940978c0..7c5d14d3a22 100644 --- a/spec/controllers/projects/mirrors_controller_spec.rb +++ b/spec/controllers/projects/mirrors_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::MirrorsController do +RSpec.describe Projects::MirrorsController do include ReactiveCachingHelpers shared_examples 'only admin is allowed when mirroring is disabled' do diff --git a/spec/controllers/projects/notes_controller_spec.rb b/spec/controllers/projects/notes_controller_spec.rb index 39594ff287d..b3a83723189 100644 --- a/spec/controllers/projects/notes_controller_spec.rb +++ b/spec/controllers/projects/notes_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::NotesController do +RSpec.describe Projects::NotesController do include ProjectForksHelper let(:user) { create(:user) } @@ -37,7 +37,7 @@ describe Projects::NotesController do project.add_developer(user) end - it 'passes last_fetched_at from headers to NotesFinder' do + it 'passes last_fetched_at from headers to NotesFinder and MergeIntoNotesService' do last_fetched_at = 3.hours.ago.to_i request.headers['X-Last-Fetched-At'] = last_fetched_at @@ -46,6 +46,10 @@ describe Projects::NotesController do .with(anything, hash_including(last_fetched_at: last_fetched_at)) .and_call_original + expect(ResourceEvents::MergeIntoNotesService).to receive(:new) + .with(anything, anything, hash_including(last_fetched_at: last_fetched_at)) + .and_call_original + get :index, params: request_params end diff --git a/spec/controllers/projects/pages_controller_spec.rb b/spec/controllers/projects/pages_controller_spec.rb index 102c0b6b048..1fa8838b548 100644 --- a/spec/controllers/projects/pages_controller_spec.rb +++ b/spec/controllers/projects/pages_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::PagesController do +RSpec.describe Projects::PagesController do let(:user) { create(:user) } let(:project) { create(:project, :public) } diff --git a/spec/controllers/projects/pages_domains_controller_spec.rb b/spec/controllers/projects/pages_domains_controller_spec.rb index 40a6f77f0d6..691508d1e14 100644 --- a/spec/controllers/projects/pages_domains_controller_spec.rb +++ b/spec/controllers/projects/pages_domains_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::PagesDomainsController do +RSpec.describe Projects::PagesDomainsController do let(:user) { create(:user) } let(:project) { create(:project) } let!(:pages_domain) { create(:pages_domain, project: project) } diff --git a/spec/controllers/projects/performance_monitoring/dashboards_controller_spec.rb b/spec/controllers/projects/performance_monitoring/dashboards_controller_spec.rb index 6a53e8f3dbf..8a344a72120 100644 --- a/spec/controllers/projects/performance_monitoring/dashboards_controller_spec.rb +++ b/spec/controllers/projects/performance_monitoring/dashboards_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::PerformanceMonitoring::DashboardsController do +RSpec.describe Projects::PerformanceMonitoring::DashboardsController do let_it_be(:user) { create(:user) } let_it_be(:namespace) { create(:namespace) } let!(:project) { create(:project, :repository, name: 'dashboard-project', namespace: namespace) } diff --git a/spec/controllers/projects/pipeline_schedules_controller_spec.rb b/spec/controllers/projects/pipeline_schedules_controller_spec.rb index 635980ba93b..27a3e95896a 100644 --- a/spec/controllers/projects/pipeline_schedules_controller_spec.rb +++ b/spec/controllers/projects/pipeline_schedules_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::PipelineSchedulesController do +RSpec.describe Projects::PipelineSchedulesController do include AccessMatchersForController let_it_be(:user) { create(:user) } diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index b3d8fb94fb3..ca09d2b1428 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::PipelinesController do +RSpec.describe Projects::PipelinesController do include ApiHelpers let_it_be(:user) { create(:user) } @@ -26,10 +26,6 @@ describe Projects::PipelinesController do context 'when using persisted stages', :request_store do render_views - before do - stub_feature_flags(ci_pipeline_persisted_stages: true) - end - it 'returns serialized pipelines' do expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original @@ -66,46 +62,6 @@ describe Projects::PipelinesController do end end - context 'when using legacy stages', :request_store do - before do - stub_feature_flags(ci_pipeline_persisted_stages: false) - end - - it 'returns JSON with serialized pipelines' do - get_pipelines_index_json - - expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('pipeline') - - expect(json_response).to include('pipelines') - expect(json_response['pipelines'].count).to eq 6 - expect(json_response['count']['all']).to eq '6' - expect(json_response['count']['running']).to eq '2' - expect(json_response['count']['pending']).to eq '1' - expect(json_response['count']['finished']).to eq '3' - - json_response.dig('pipelines', 0, 'details', 'stages').tap do |stages| - expect(stages.count).to eq 3 - end - end - - it 'does not execute N+1 queries' do - get_pipelines_index_json - - control_count = ActiveRecord::QueryRecorder.new do - get_pipelines_index_json - end.count - - create_all_pipeline_types - - # There appears to be one extra query for Pipelines#has_warnings? for some reason - expect { get_pipelines_index_json }.not_to exceed_query_limit(control_count + 1) - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response['pipelines'].count).to eq 12 - end - end - it 'does not include coverage data for the pipelines' do get_pipelines_index_json @@ -215,6 +171,40 @@ describe Projects::PipelinesController do end end + context 'filter by status' do + context 'when pipelines with the status exists' do + it 'returns matched pipelines' do + get_pipelines_index_json(status: 'success') + + check_pipeline_response(returned: 1, all: 1, running: 0, pending: 0, finished: 1) + end + + context 'when filter by unrelated scope' do + it 'returns empty list' do + get_pipelines_index_json(status: 'success', scope: 'running') + + check_pipeline_response(returned: 0, all: 1, running: 0, pending: 0, finished: 1) + end + end + end + + context 'when no pipeline with the status exists' do + it 'returns empty list' do + get_pipelines_index_json(status: 'manual') + + check_pipeline_response(returned: 0, all: 0, running: 0, pending: 0, finished: 0) + end + end + + context 'when invalid status' do + it 'returns all list' do + get_pipelines_index_json(status: 'invalid-status') + + check_pipeline_response(returned: 6, all: 6, running: 2, pending: 1, finished: 3) + end + end + end + def get_pipelines_index_json(params = {}) get :index, params: { namespace_id: project.namespace, @@ -548,6 +538,39 @@ describe Projects::PipelinesController do end end + describe 'GET dag.json' do + let(:pipeline) { create(:ci_pipeline, project: project) } + + before do + create_build('build', 1, 'build') + create_build('test', 2, 'test', scheduling_type: 'dag').tap do |job| + create(:ci_build_need, build: job, name: 'build') + end + end + + it 'returns the pipeline with DAG serialization' do + get :dag, params: { namespace_id: project.namespace, project_id: project, id: pipeline }, format: :json + + expect(response).to have_gitlab_http_status(:ok) + + expect(json_response.fetch('stages')).not_to be_empty + + build_stage = json_response['stages'].first + expect(build_stage.fetch('name')).to eq 'build' + expect(build_stage.fetch('groups').first.fetch('jobs')) + .to eq [{ 'name' => 'build', 'scheduling_type' => 'stage' }] + + test_stage = json_response['stages'].last + expect(test_stage.fetch('name')).to eq 'test' + expect(test_stage.fetch('groups').first.fetch('jobs')) + .to eq [{ 'name' => 'test', 'scheduling_type' => 'dag', 'needs' => ['build'] }] + end + + def create_build(stage, stage_idx, name, params = {}) + create(:ci_build, pipeline: pipeline, stage: stage, stage_idx: stage_idx, name: name, **params) + end + end + describe 'GET stages.json' do let(:pipeline) { create(:ci_pipeline, project: project) } @@ -685,7 +708,7 @@ describe Projects::PipelinesController do end shared_examples 'creates a pipeline' do - it do + specify do expect { post_request }.to change { project.ci_pipelines.count }.by(1) pipeline = project.ci_pipelines.last diff --git a/spec/controllers/projects/pipelines_settings_controller_spec.rb b/spec/controllers/projects/pipelines_settings_controller_spec.rb index 789b2104d3c..ad631b7c3da 100644 --- a/spec/controllers/projects/pipelines_settings_controller_spec.rb +++ b/spec/controllers/projects/pipelines_settings_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::PipelinesSettingsController do +RSpec.describe Projects::PipelinesSettingsController do let_it_be(:user) { create(:user) } let_it_be(:project_auto_devops) { create(:project_auto_devops) } let(:project) { project_auto_devops.project } diff --git a/spec/controllers/projects/project_members_controller_spec.rb b/spec/controllers/projects/project_members_controller_spec.rb index f354bba902a..7457e4c5023 100644 --- a/spec/controllers/projects/project_members_controller_spec.rb +++ b/spec/controllers/projects/project_members_controller_spec.rb @@ -2,7 +2,7 @@ require('spec_helper') -describe Projects::ProjectMembersController do +RSpec.describe Projects::ProjectMembersController do let(:user) { create(:user) } let(:group) { create(:group, :public) } let(:project) { create(:project, :public) } diff --git a/spec/controllers/projects/prometheus/alerts_controller_spec.rb b/spec/controllers/projects/prometheus/alerts_controller_spec.rb index e936cb5916e..6e3148231bd 100644 --- a/spec/controllers/projects/prometheus/alerts_controller_spec.rb +++ b/spec/controllers/projects/prometheus/alerts_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Prometheus::AlertsController do +RSpec.describe Projects::Prometheus::AlertsController do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:environment) { create(:environment, project: project) } diff --git a/spec/controllers/projects/prometheus/metrics_controller_spec.rb b/spec/controllers/projects/prometheus/metrics_controller_spec.rb index 36f694cda29..c7c3be20f29 100644 --- a/spec/controllers/projects/prometheus/metrics_controller_spec.rb +++ b/spec/controllers/projects/prometheus/metrics_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Prometheus::MetricsController do +RSpec.describe Projects::Prometheus::MetricsController do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:prometheus_project) } diff --git a/spec/controllers/projects/protected_branches_controller_spec.rb b/spec/controllers/projects/protected_branches_controller_spec.rb index 262f77a7328..09eb1a45c73 100644 --- a/spec/controllers/projects/protected_branches_controller_spec.rb +++ b/spec/controllers/projects/protected_branches_controller_spec.rb @@ -2,7 +2,7 @@ require('spec_helper') -describe Projects::ProtectedBranchesController do +RSpec.describe Projects::ProtectedBranchesController do let(:project) { create(:project, :repository) } let(:protected_branch) { create(:protected_branch, project: project) } let(:project_params) { { namespace_id: project.namespace.to_param, project_id: project } } diff --git a/spec/controllers/projects/protected_tags_controller_spec.rb b/spec/controllers/projects/protected_tags_controller_spec.rb index a900947d82e..2c2240cb0d0 100644 --- a/spec/controllers/projects/protected_tags_controller_spec.rb +++ b/spec/controllers/projects/protected_tags_controller_spec.rb @@ -2,7 +2,7 @@ require('spec_helper') -describe Projects::ProtectedTagsController do +RSpec.describe Projects::ProtectedTagsController do describe "GET #index" do let(:project) { create(:project_empty_repo, :public) } diff --git a/spec/controllers/projects/raw_controller_spec.rb b/spec/controllers/projects/raw_controller_spec.rb index 4a684dcfbc6..5f10343eb76 100644 --- a/spec/controllers/projects/raw_controller_spec.rb +++ b/spec/controllers/projects/raw_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::RawController do +RSpec.describe Projects::RawController do include RepoHelpers let(:project) { create(:project, :public, :repository) } diff --git a/spec/controllers/projects/refs_controller_spec.rb b/spec/controllers/projects/refs_controller_spec.rb index b043e7f2538..a6a4aff7ce9 100644 --- a/spec/controllers/projects/refs_controller_spec.rb +++ b/spec/controllers/projects/refs_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::RefsController do +RSpec.describe Projects::RefsController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } @@ -73,7 +73,7 @@ describe Projects::RefsController do cache_key = "projects/#{project.id}/logs/#{project.commit.id}/#{path}/25" expect(Rails.cache.fetch(cache_key)).to eq(['logs', 50]) - expect(response.headers['More-Logs-Offset']).to eq(50) + expect(response.headers['More-Logs-Offset']).to eq("50") end end end diff --git a/spec/controllers/projects/registry/repositories_controller_spec.rb b/spec/controllers/projects/registry/repositories_controller_spec.rb index badb84f9b50..098fa9bac2c 100644 --- a/spec/controllers/projects/registry/repositories_controller_spec.rb +++ b/spec/controllers/projects/registry/repositories_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Registry::RepositoriesController do +RSpec.describe Projects::Registry::RepositoriesController do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :private) } @@ -46,7 +46,7 @@ describe Projects::Registry::RepositoriesController do context 'when root container repository is not created' do context 'when there are tags for this repository' do before do - stub_container_registry_tags(repository: project.full_path, + stub_container_registry_tags(repository: :any, tags: %w[rc1 latest]) end diff --git a/spec/controllers/projects/registry/tags_controller_spec.rb b/spec/controllers/projects/registry/tags_controller_spec.rb index 5ab32b7d81d..6adee35b60a 100644 --- a/spec/controllers/projects/registry/tags_controller_spec.rb +++ b/spec/controllers/projects/registry/tags_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Registry::TagsController do +RSpec.describe Projects::Registry::TagsController do let(:user) { create(:user) } let(:project) { create(:project, :private) } diff --git a/spec/controllers/projects/releases/evidences_controller_spec.rb b/spec/controllers/projects/releases/evidences_controller_spec.rb index d3808087681..d5a9665d6a5 100644 --- a/spec/controllers/projects/releases/evidences_controller_spec.rb +++ b/spec/controllers/projects/releases/evidences_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Releases::EvidencesController do +RSpec.describe Projects::Releases::EvidencesController do let!(:project) { create(:project, :repository, :public) } let_it_be(:private_project) { create(:project, :repository, :private) } let_it_be(:developer) { create(:user) } @@ -31,8 +31,8 @@ describe Projects::Releases::EvidencesController do end describe 'GET #show' do - let_it_be(:tag_name) { "v1.1.0-evidence" } - let!(:release) { create(:release, :with_evidence, project: project, tag: tag_name) } + let(:tag_name) { "v1.1.0-evidence" } + let!(:release) { create(:release, project: project, tag: tag_name) } let(:evidence) { release.evidences.first } let(:tag) { CGI.escape(release.tag) } let(:format) { :json } @@ -48,6 +48,8 @@ describe Projects::Releases::EvidencesController do end before do + ::Releases::CreateEvidenceService.new(release).execute + sign_in(user) end @@ -84,14 +86,9 @@ describe Projects::Releases::EvidencesController do end context 'when release is associated to a milestone which includes an issue' do - let_it_be(:project) { create(:project, :repository, :public) } - let_it_be(:issue) { create(:issue, project: project) } - let_it_be(:milestone) { create(:milestone, project: project, issues: [issue]) } - let_it_be(:release) { create(:release, project: project, tag: tag_name, milestones: [milestone]) } - - before do - create(:evidence, release: release) - end + let(:issue) { create(:issue, project: project) } + let(:milestone) { create(:milestone, project: project, issues: [issue]) } + let(:release) { create(:release, project: project, tag: tag_name, milestones: [milestone]) } shared_examples_for 'does not show the issue in evidence' do it do @@ -111,7 +108,9 @@ describe Projects::Releases::EvidencesController do end end - shared_examples_for 'safely expose evidence' do + context 'when user is non-project member' do + let(:user) { create(:user) } + it_behaves_like 'does not show the issue in evidence' context 'when the issue is confidential' do @@ -127,28 +126,50 @@ describe Projects::Releases::EvidencesController do end context 'when project is private' do - let!(:project) { create(:project, :repository, :private) } + let(:project) { create(:project, :repository, :private) } it_behaves_like 'evidence not found' end context 'when project restricts the visibility of issues to project members only' do - let!(:project) { create(:project, :repository, :issues_private) } + let(:project) { create(:project, :repository, :issues_private) } it_behaves_like 'evidence not found' end end - context 'when user is non-project member' do - let(:user) { create(:user) } - - it_behaves_like 'safely expose evidence' - end - context 'when user is auditor', if: Gitlab.ee? do let(:user) { create(:user, :auditor) } - it_behaves_like 'safely expose evidence' + it_behaves_like 'does not show the issue in evidence' + + context 'when the issue is confidential' do + let(:issue) { create(:issue, :confidential, project: project) } + + it_behaves_like 'does not show the issue in evidence' + end + + context 'when the user is the author of the confidential issue' do + let(:issue) { create(:issue, :confidential, project: project, author: user) } + + it_behaves_like 'does not show the issue in evidence' + end + + context 'when project is private' do + let(:project) { create(:project, :repository, :private) } + + it 'returns evidence ' do + subject + + expect(json_response).to eq(evidence.summary) + end + end + + context 'when project restricts the visibility of issues to project members only' do + let(:project) { create(:project, :repository, :issues_private) } + + it_behaves_like 'evidence not found' + end end context 'when external authorization control is enabled' do diff --git a/spec/controllers/projects/releases_controller_spec.rb b/spec/controllers/projects/releases_controller_spec.rb index 45f4433ed0a..96c38c1b726 100644 --- a/spec/controllers/projects/releases_controller_spec.rb +++ b/spec/controllers/projects/releases_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::ReleasesController do +RSpec.describe Projects::ReleasesController do let!(:project) { create(:project, :repository, :public) } let_it_be(:private_project) { create(:project, :repository, :private) } let_it_be(:developer) { create(:user) } diff --git a/spec/controllers/projects/repositories_controller_spec.rb b/spec/controllers/projects/repositories_controller_spec.rb index 42032b4cad0..97eea7c7e9d 100644 --- a/spec/controllers/projects/repositories_controller_spec.rb +++ b/spec/controllers/projects/repositories_controller_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe Projects::RepositoriesController do +RSpec.describe Projects::RepositoriesController do let(:project) { create(:project, :repository) } describe "GET archive" do diff --git a/spec/controllers/projects/runners_controller_spec.rb b/spec/controllers/projects/runners_controller_spec.rb index 1893180fe9b..66f20bd50c4 100644 --- a/spec/controllers/projects/runners_controller_spec.rb +++ b/spec/controllers/projects/runners_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::RunnersController do +RSpec.describe Projects::RunnersController do let(:user) { create(:user) } let(:project) { create(:project) } let(:runner) { create(:ci_runner, :project, projects: [project]) } diff --git a/spec/controllers/projects/serverless/functions_controller_spec.rb b/spec/controllers/projects/serverless/functions_controller_spec.rb index 203e1e49994..3071d0b7f54 100644 --- a/spec/controllers/projects/serverless/functions_controller_spec.rb +++ b/spec/controllers/projects/serverless/functions_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Serverless::FunctionsController do +RSpec.describe Projects::Serverless::FunctionsController do include KubernetesHelpers include ReactiveCachingHelpers diff --git a/spec/controllers/projects/service_hook_logs_controller_spec.rb b/spec/controllers/projects/service_hook_logs_controller_spec.rb index a5130cd6e32..97fb31f0546 100644 --- a/spec/controllers/projects/service_hook_logs_controller_spec.rb +++ b/spec/controllers/projects/service_hook_logs_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::ServiceHookLogsController do +RSpec.describe Projects::ServiceHookLogsController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:service) { create(:drone_ci_service, project: project) } diff --git a/spec/controllers/projects/services_controller_spec.rb b/spec/controllers/projects/services_controller_spec.rb index c669119fa4e..04c74dfdefe 100644 --- a/spec/controllers/projects/services_controller_spec.rb +++ b/spec/controllers/projects/services_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::ServicesController do +RSpec.describe Projects::ServicesController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:service) { create(:jira_service, project: project) } @@ -134,24 +134,50 @@ describe Projects::ServicesController do describe 'PUT #update' do describe 'as HTML' do let(:service_params) { { active: true } } + let(:params) { project_params(service: service_params) } + + let(:message) { 'Jira activated.' } + let(:redirect_url) { project_settings_integrations_path(project) } before do - put :update, params: project_params(service: service_params) + put :update, params: params + end + + shared_examples 'service update' do + it 'redirects to the correct url with a flash message' do + expect(response).to redirect_to(redirect_url) + expect(flash[:notice]).to eq(message) + end end context 'when param `active` is set to true' do - it 'activates the service and redirects to integrations paths' do - expect(response).to redirect_to(project_settings_integrations_path(project)) - expect(flash[:notice]).to eq 'Jira activated.' + let(:params) { project_params(service: service_params, redirect_to: redirect) } + + context 'when redirect_to param is present' do + let(:redirect) { '/redirect_here' } + let(:redirect_url) { redirect } + + it_behaves_like 'service update' + end + + context 'when redirect_to is an external domain' do + let(:redirect) { 'http://examle.com' } + + it_behaves_like 'service update' + end + + context 'when redirect_to param is an empty string' do + let(:redirect) { '' } + + it_behaves_like 'service update' end end context 'when param `active` is set to false' do let(:service_params) { { active: false } } + let(:message) { 'Jira settings saved, but not activated.' } - it 'does not activate the service but saves the settings' do - expect(flash[:notice]).to eq 'Jira settings saved, but not activated.' - end + it_behaves_like 'service update' end end diff --git a/spec/controllers/projects/settings/access_tokens_controller_spec.rb b/spec/controllers/projects/settings/access_tokens_controller_spec.rb index 884a5bc2836..4743ab2b7c1 100644 --- a/spec/controllers/projects/settings/access_tokens_controller_spec.rb +++ b/spec/controllers/projects/settings/access_tokens_controller_spec.rb @@ -2,7 +2,7 @@ require('spec_helper') -describe Projects::Settings::AccessTokensController do +RSpec.describe Projects::Settings::AccessTokensController do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } diff --git a/spec/controllers/projects/settings/ci_cd_controller_spec.rb b/spec/controllers/projects/settings/ci_cd_controller_spec.rb index 6891af54eb4..8498ff49826 100644 --- a/spec/controllers/projects/settings/ci_cd_controller_spec.rb +++ b/spec/controllers/projects/settings/ci_cd_controller_spec.rb @@ -2,7 +2,7 @@ require('spec_helper') -describe Projects::Settings::CiCdController do +RSpec.describe Projects::Settings::CiCdController do let_it_be(:user) { create(:user) } let_it_be(:project_auto_devops) { create(:project_auto_devops) } let(:project) { project_auto_devops.project } diff --git a/spec/controllers/projects/settings/integrations_controller_spec.rb b/spec/controllers/projects/settings/integrations_controller_spec.rb index 5d9fe3da912..0652786c787 100644 --- a/spec/controllers/projects/settings/integrations_controller_spec.rb +++ b/spec/controllers/projects/settings/integrations_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Settings::IntegrationsController do +RSpec.describe Projects::Settings::IntegrationsController do let(:project) { create(:project, :public) } let(:user) { create(:user) } diff --git a/spec/controllers/projects/settings/operations_controller_spec.rb b/spec/controllers/projects/settings/operations_controller_spec.rb index c9afff0b73d..6b440e910ad 100644 --- a/spec/controllers/projects/settings/operations_controller_spec.rb +++ b/spec/controllers/projects/settings/operations_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Settings::OperationsController do +RSpec.describe Projects::Settings::OperationsController do let_it_be(:user) { create(:user) } let_it_be(:project, reload: true) { create(:project) } diff --git a/spec/controllers/projects/settings/repository_controller_spec.rb b/spec/controllers/projects/settings/repository_controller_spec.rb index fb9cdd860dc..46dba691bc4 100644 --- a/spec/controllers/projects/settings/repository_controller_spec.rb +++ b/spec/controllers/projects/settings/repository_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Settings::RepositoryController do +RSpec.describe Projects::Settings::RepositoryController do let(:project) { create(:project_empty_repo, :public) } let(:user) { create(:user) } diff --git a/spec/controllers/projects/snippets_controller_spec.rb b/spec/controllers/projects/snippets_controller_spec.rb index b5f4929d8ce..8bbfaa8d327 100644 --- a/spec/controllers/projects/snippets_controller_spec.rb +++ b/spec/controllers/projects/snippets_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::SnippetsController do +RSpec.describe Projects::SnippetsController do include Gitlab::Routing let_it_be(:user) { create(:user) } diff --git a/spec/controllers/projects/stages_controller_spec.rb b/spec/controllers/projects/stages_controller_spec.rb index c38e3d2544f..dcf8607ae18 100644 --- a/spec/controllers/projects/stages_controller_spec.rb +++ b/spec/controllers/projects/stages_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::StagesController do +RSpec.describe Projects::StagesController do let(:user) { create(:user) } let(:project) { create(:project, :repository) } diff --git a/spec/controllers/projects/starrers_controller_spec.rb b/spec/controllers/projects/starrers_controller_spec.rb index 5774ff7c576..66888fa3024 100644 --- a/spec/controllers/projects/starrers_controller_spec.rb +++ b/spec/controllers/projects/starrers_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::StarrersController do +RSpec.describe Projects::StarrersController do let(:user_1) { create(:user, name: 'John') } let(:user_2) { create(:user, name: 'Michael') } let(:private_user) { create(:user, name: 'Michael Douglas', private_profile: true) } diff --git a/spec/controllers/projects/static_site_editor_controller_spec.rb b/spec/controllers/projects/static_site_editor_controller_spec.rb index 7b470254de1..384218504b9 100644 --- a/spec/controllers/projects/static_site_editor_controller_spec.rb +++ b/spec/controllers/projects/static_site_editor_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::StaticSiteEditorController do +RSpec.describe Projects::StaticSiteEditorController do let_it_be(:project) { create(:project, :public, :repository) } let_it_be(:user) { create(:user) } diff --git a/spec/controllers/projects/tags/releases_controller_spec.rb b/spec/controllers/projects/tags/releases_controller_spec.rb index cb12e074732..b3d4d944440 100644 --- a/spec/controllers/projects/tags/releases_controller_spec.rb +++ b/spec/controllers/projects/tags/releases_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::Tags::ReleasesController do +RSpec.describe Projects::Tags::ReleasesController do let!(:project) { create(:project, :repository) } let!(:user) { create(:user) } let!(:release) { create(:release, project: project) } @@ -16,7 +16,7 @@ describe Projects::Tags::ReleasesController do describe 'GET #edit' do it 'initializes a new release' do tag_id = release.tag - project.releases.destroy_all # rubocop: disable DestroyAll + project.releases.destroy_all # rubocop: disable Cop/DestroyAll response = get :edit, params: { namespace_id: project.namespace, project_id: project, tag_id: tag_id } diff --git a/spec/controllers/projects/tags_controller_spec.rb b/spec/controllers/projects/tags_controller_spec.rb index 15ef1c65c53..122d1b072d0 100644 --- a/spec/controllers/projects/tags_controller_spec.rb +++ b/spec/controllers/projects/tags_controller_spec.rb @@ -2,10 +2,11 @@ require 'spec_helper' -describe Projects::TagsController do +RSpec.describe Projects::TagsController do let(:project) { create(:project, :public, :repository) } let!(:release) { create(:release, project: project) } let!(:invalid_release) { create(:release, project: project, tag: 'does-not-exist') } + let(:user) { create(:user) } describe 'GET index' do before do @@ -61,4 +62,69 @@ describe Projects::TagsController do end end end + + describe 'POST #create' do + before do + project.add_developer(user) + sign_in(user) + end + + let(:release_description) { nil } + let(:request) do + post(:create, params: { + namespace_id: project.namespace.to_param, + project_id: project, + tag_name: '1.0', + ref: 'master', + release_description: release_description + }) + end + + it 'creates tag' do + request + + expect(response).to have_gitlab_http_status(:found) + expect(project.repository.find_tag('1.0')).to be_present + end + + # TODO: remove this with the release creation moved to it's own form https://gitlab.com/gitlab-org/gitlab/-/issues/214245 + context 'when release description is set' do + let(:release_description) { 'some release description' } + + it 'creates tag and release' do + request + + expect(response).to have_gitlab_http_status(:found) + expect(project.repository.find_tag('1.0')).to be_present + + release = project.releases.find_by_tag!('1.0') + + expect(release).to be_present + expect(release.description).to eq(release_description) + end + + it 'passes the last pipeline for evidence creation', :sidekiq_inline do + sha = project.repository.commit('master').sha + create(:ci_empty_pipeline, sha: sha, project: project) # old pipeline + pipeline = create(:ci_empty_pipeline, sha: sha, project: project) + + # simulating pipeline creation by new tag + expect_any_instance_of(Repository).to receive(:add_tag).and_wrap_original do |m, *args| + create(:ci_empty_pipeline, sha: sha, project: project) + m.call(*args) + end + + expect_next_instance_of(Releases::CreateEvidenceService, anything, pipeline: pipeline) do |service| + expect(service).to receive(:execute).and_call_original + end + + request + + release = project.releases.find_by_tag!('1.0') + + expect(release).to be_present + expect(release.description).to eq(release_description) + end + end + end end diff --git a/spec/controllers/projects/templates_controller_spec.rb b/spec/controllers/projects/templates_controller_spec.rb index fcd9b4aa8bd..40632e0dea7 100644 --- a/spec/controllers/projects/templates_controller_spec.rb +++ b/spec/controllers/projects/templates_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::TemplatesController do +RSpec.describe Projects::TemplatesController do let(:project) { create(:project, :repository, :private) } let(:user) { create(:user) } let(:file_path_1) { '.gitlab/issue_templates/issue_template.md' } diff --git a/spec/controllers/projects/todos_controller_spec.rb b/spec/controllers/projects/todos_controller_spec.rb index b7d40d2a452..e1e1e455094 100644 --- a/spec/controllers/projects/todos_controller_spec.rb +++ b/spec/controllers/projects/todos_controller_spec.rb @@ -2,7 +2,7 @@ require('spec_helper') -describe Projects::TodosController do +RSpec.describe Projects::TodosController do let(:user) { create(:user) } let(:project) { create(:project) } let(:issue) { create(:issue, project: project) } diff --git a/spec/controllers/projects/tree_controller_spec.rb b/spec/controllers/projects/tree_controller_spec.rb index 96838383540..f6ec04d4dd7 100644 --- a/spec/controllers/projects/tree_controller_spec.rb +++ b/spec/controllers/projects/tree_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::TreeController do +RSpec.describe Projects::TreeController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } diff --git a/spec/controllers/projects/uploads_controller_spec.rb b/spec/controllers/projects/uploads_controller_spec.rb index bb5415ee62c..dda58f06a37 100644 --- a/spec/controllers/projects/uploads_controller_spec.rb +++ b/spec/controllers/projects/uploads_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::UploadsController do +RSpec.describe Projects::UploadsController do include WorkhorseHelpers let(:model) { create(:project, :public) } diff --git a/spec/controllers/projects/usage_ping_controller_spec.rb b/spec/controllers/projects/usage_ping_controller_spec.rb index a68967c228f..9ace072d561 100644 --- a/spec/controllers/projects/usage_ping_controller_spec.rb +++ b/spec/controllers/projects/usage_ping_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::UsagePingController do +RSpec.describe Projects::UsagePingController do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index 21e106660d0..8bb4c2dae4b 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Projects::VariablesController do +RSpec.describe Projects::VariablesController do let(:project) { create(:project) } let(:user) { create(:user) } diff --git a/spec/controllers/projects/web_ide_terminals_controller_spec.rb b/spec/controllers/projects/web_ide_terminals_controller_spec.rb new file mode 100644 index 00000000000..2ae5899c258 --- /dev/null +++ b/spec/controllers/projects/web_ide_terminals_controller_spec.rb @@ -0,0 +1,304 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Projects::WebIdeTerminalsController do + let_it_be(:owner) { create(:owner) } + let_it_be(:admin) { create(:admin) } + let_it_be(:maintainer) { create(:user) } + let_it_be(:developer) { create(:user) } + let_it_be(:reporter) { create(:user) } + let_it_be(:guest) { create(:user) } + let_it_be(:project) { create(:project, :private, :repository, namespace: owner.namespace) } + let(:pipeline) { create(:ci_pipeline, project: project, source: :webide, config_source: :webide_source, user: user) } + let(:job) { create(:ci_build, pipeline: pipeline, user: user, project: project) } + let(:user) { maintainer } + + before do + project.add_maintainer(maintainer) + project.add_developer(developer) + project.add_reporter(reporter) + project.add_guest(guest) + + sign_in(user) + end + + shared_examples 'terminal access rights' do + context 'with admin' do + let(:user) { admin } + + context 'when admin mode is enabled', :enable_admin_mode do + it 'returns 200' do + expect(response).to have_gitlab_http_status(:ok) + end + end + + context 'when admin mode is disabled' do + it 'returns 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + context 'with owner' do + let(:user) { owner } + + it 'returns 200' do + expect(response).to have_gitlab_http_status(:ok) + end + end + + context 'with maintainer' do + let(:user) { maintainer } + + it 'returns 200' do + expect(response).to have_gitlab_http_status(:ok) + end + end + + context 'with developer' do + let(:user) { developer } + + it 'returns 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'with reporter' do + let(:user) { reporter } + + it 'returns 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'with guest' do + let(:user) { guest } + + it 'returns 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'with non member' do + let(:user) { create(:user) } + + it 'returns 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + shared_examples 'when pipeline is not from a webide source' do + context 'with admin' do + let(:user) { admin } + let(:pipeline) { create(:ci_pipeline, project: project, source: :chat, user: user) } + + it 'returns 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + describe 'GET show' do + before do + get(:show, params: { namespace_id: project.namespace.to_param, project_id: project, id: job.id }) + end + + it_behaves_like 'terminal access rights' + it_behaves_like 'when pipeline is not from a webide source' + end + + describe 'POST check_config' do + let(:result) { { status: :success } } + + before do + allow_next_instance_of(::Ci::WebIdeConfigService) do |instance| + allow(instance).to receive(:execute).and_return(result) + end + + post :check_config, params: { + namespace_id: project.namespace.to_param, + project_id: project.to_param, + branch: 'master' + } + end + + it_behaves_like 'terminal access rights' + + context 'when invalid config file' do + let(:user) { admin } + let(:result) { { status: :error } } + + it 'returns 422', :enable_admin_mode do + expect(response).to have_gitlab_http_status(:unprocessable_entity) + end + end + end + + describe 'POST create' do + let(:branch) { 'master' } + + subject do + post :create, params: { + namespace_id: project.namespace.to_param, + project_id: project.to_param, + branch: branch + } + end + + context 'when terminal job is created successfully' do + let(:build) { create(:ci_build, project: project) } + let(:pipeline) { build.pipeline } + + before do + allow_next_instance_of(::Ci::CreateWebIdeTerminalService) do |instance| + allow(instance).to receive(:execute).and_return(status: :success, pipeline: pipeline) + end + end + + context 'access rights' do + before do + subject + end + + it_behaves_like 'terminal access rights' + end + + it 'increases the web ide terminal counter' do + expect(Gitlab::UsageDataCounters::WebIdeCounter).to receive(:increment_terminals_count) + + subject + end + end + + shared_examples 'web ide terminal usage counter' do + it 'does not increase', :enable_admin_mode do + expect(Gitlab::UsageDataCounters::WebIdeCounter).not_to receive(:increment_terminals_count) + + subject + end + end + + context 'when branch does not exist' do + let(:user) { admin } + let(:branch) { 'foobar' } + + it 'returns 400', :enable_admin_mode do + subject + + expect(response).to have_gitlab_http_status(:bad_request) + end + + it_behaves_like 'web ide terminal usage counter' + end + + context 'when there is an error creating the job' do + let(:user) { admin } + + before do + allow_next_instance_of(::Ci::CreateWebIdeTerminalService) do |instance| + allow(instance).to receive(:execute).and_return(status: :error, message: 'foobar') + end + end + + it 'returns 400', :enable_admin_mode do + subject + + expect(response).to have_gitlab_http_status(:bad_request) + end + + it_behaves_like 'web ide terminal usage counter' + end + + context 'when the current build is nil' do + let(:user) { admin } + + before do + allow(pipeline).to receive(:builds).and_return([]) + allow_next_instance_of(::Ci::CreateWebIdeTerminalService) do |instance| + allow(instance).to receive(:execute).and_return(status: :success, pipeline: pipeline) + end + end + + it 'returns 400', :enable_admin_mode do + subject + + expect(response).to have_gitlab_http_status(:bad_request) + end + + it_behaves_like 'web ide terminal usage counter' + end + end + + describe 'POST cancel' do + let(:job) { create(:ci_build, :running, pipeline: pipeline, user: user, project: project) } + + before do + post(:cancel, params: { + namespace_id: project.namespace.to_param, + project_id: project.to_param, + id: job.id + }) + end + + it_behaves_like 'terminal access rights' + it_behaves_like 'when pipeline is not from a webide source' + + context 'when job is not cancelable' do + let!(:job) { create(:ci_build, :failed, pipeline: pipeline, user: user) } + + it 'returns 422' do + expect(response).to have_gitlab_http_status(:unprocessable_entity) + end + end + end + + describe 'POST retry' do + let(:status) { :failed } + let(:job) { create(:ci_build, status, pipeline: pipeline, user: user, project: project) } + + before do + post(:retry, params: { + namespace_id: project.namespace.to_param, + project_id: project.to_param, + id: job.id + }) + end + + it_behaves_like 'terminal access rights' + it_behaves_like 'when pipeline is not from a webide source' + + context 'when job is not retryable' do + let(:status) { :running } + + it 'returns 422' do + expect(response).to have_gitlab_http_status(:unprocessable_entity) + end + end + + context 'when job is cancelled' do + let(:status) { :canceled } + + it 'returns 200' do + expect(response).to have_gitlab_http_status(:ok) + end + end + + context 'when job fails' do + let(:status) { :failed } + + it 'returns 200' do + expect(response).to have_gitlab_http_status(:ok) + end + end + + context 'when job is successful' do + let(:status) { :success } + + it 'returns 200' do + expect(response).to have_gitlab_http_status(:ok) + end + end + end +end diff --git a/spec/controllers/projects/wikis_controller_spec.rb b/spec/controllers/projects/wikis_controller_spec.rb index b4bbf76ce18..4e58822b613 100644 --- a/spec/controllers/projects/wikis_controller_spec.rb +++ b/spec/controllers/projects/wikis_controller_spec.rb @@ -2,283 +2,9 @@ require 'spec_helper' -describe Projects::WikisController do - let_it_be(:project) { create(:project, :public, :repository) } - let(:user) { project.owner } - let(:project_wiki) { ProjectWiki.new(project, user) } - let(:wiki) { project_wiki.wiki } - let(:wiki_title) { 'page title test' } - - before do - create_page(wiki_title, 'hello world') - - sign_in(user) - end - - after do - destroy_page(wiki_title) - end - - describe 'GET #new' do - subject { get :new, params: { namespace_id: project.namespace, project_id: project } } - - it 'redirects to #show and appends a `random_title` param' do - subject - - expect(response).to have_gitlab_http_status(:found) - expect(Rails.application.routes.recognize_path(response.redirect_url)).to include( - controller: 'projects/wikis', - action: 'show' - ) - expect(response.redirect_url).to match(/\?random_title=true\Z/) - end - end - - describe 'GET #pages' do - subject { get :pages, params: { namespace_id: project.namespace, project_id: project, id: wiki_title } } - - it 'does not load the pages content' do - expect(controller).to receive(:load_wiki).and_return(project_wiki) - - expect(project_wiki).to receive(:list_pages).twice.and_call_original - - subject - end - end - - describe 'GET #history' do - before do - allow(controller) - .to receive(:can?) - .with(any_args) - .and_call_original - - # The :create_wiki permission is irrelevant to reading history. - expect(controller) - .not_to receive(:can?) - .with(anything, :create_wiki, any_args) - - allow(controller) - .to receive(:can?) - .with(anything, :read_wiki, any_args) - .and_return(allow_read_wiki) - end - - shared_examples 'fetching history' do |expected_status| - before do - get :history, params: { namespace_id: project.namespace, project_id: project, id: wiki_title } - end - - it "returns status #{expected_status}" do - expect(response).to have_gitlab_http_status(expected_status) - end - end - - it_behaves_like 'fetching history', :ok do - let(:allow_read_wiki) { true } - - it 'assigns @page_versions' do - expect(assigns(:page_versions)).to be_present - end - end - - it_behaves_like 'fetching history', :not_found do - let(:allow_read_wiki) { false } - end - end - - describe 'GET #show' do - render_views - - let(:random_title) { nil } - - subject { get :show, params: { namespace_id: project.namespace, project_id: project, id: id, random_title: random_title } } - - context 'when page exists' do - let(:id) { wiki_title } - - it 'limits the retrieved pages for the sidebar' do - subject - - expect(response).to have_gitlab_http_status(:ok) - expect(assigns(:page).title).to eq(wiki_title) - expect(assigns(:sidebar_wiki_entries)).to contain_exactly(an_instance_of(WikiPage)) - expect(assigns(:sidebar_limited)).to be(false) - end - - context 'when page content encoding is invalid' do - it 'sets flash error' do - allow(controller).to receive(:valid_encoding?).and_return(false) - - subject - - expect(response).to have_gitlab_http_status(:ok) - expect(flash[:notice]).to eq(_('The content of this page is not encoded in UTF-8. Edits can only be made via the Git repository.')) - end - end - end - - context 'when the page does not exist' do - let(:id) { 'does not exist' } - - before do - subject - end - - it 'builds a new wiki page with the id as the title' do - expect(assigns(:page).title).to eq(id) - end - - context 'when a random_title param is present' do - let(:random_title) { true } - - it 'builds a new wiki page with no title' do - expect(assigns(:page).title).to be_empty - end - end - end - - context 'when page is a file' do - include WikiHelpers - - let(:id) { upload_file_to_wiki(project, user, file_name) } - - context 'when file is an image' do - let(:file_name) { 'dk.png' } - - it 'delivers the image' do - subject - - expect(response.headers['Content-Disposition']).to match(/^inline/) - expect(response.headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true" - end - - context 'when file is a svg' do - let(:file_name) { 'unsanitized.svg' } - - it 'delivers the image' do - subject - - expect(response.headers['Content-Disposition']).to match(/^inline/) - expect(response.headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true" - end - end - - it_behaves_like 'project cache control headers' - end - - context 'when file is a pdf' do - let(:file_name) { 'git-cheat-sheet.pdf' } - - it 'sets the content type to sets the content response headers' do - subject - - expect(response.headers['Content-Disposition']).to match(/^inline/) - expect(response.headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true" - end - - it_behaves_like 'project cache control headers' - end - end - end - - describe 'POST #preview_markdown' do - it 'renders json in a correct format' do - post :preview_markdown, params: { namespace_id: project.namespace, project_id: project, id: 'page/path', text: '*Markdown* text' } - - expect(json_response.keys).to match_array(%w(body references)) - end - end - - describe 'GET #edit' do - subject { get(:edit, params: { namespace_id: project.namespace, project_id: project, id: wiki_title }) } - - context 'when page content encoding is invalid' do - it 'redirects to show' do - allow(controller).to receive(:valid_encoding?).and_return(false) - - subject - - expect(response).to redirect_to_wiki(project, project_wiki.list_pages.first) - end - end - - context 'when the page has nil content' do - let(:page) { create(:wiki_page) } - - it 'redirects to show' do - allow(page).to receive(:content).and_return(nil) - allow(controller).to receive(:find_page).and_return(page) - - subject - - expect(response).to redirect_to_wiki(project, page) - end - end - - context 'when page content encoding is valid' do - render_views - - it 'shows the edit page' do - subject - - expect(response).to have_gitlab_http_status(:ok) - expect(response.body).to include(s_('Wiki|Edit Page')) - end - end - end - - describe 'PATCH #update' do - let(:new_title) { 'New title' } - let(:new_content) { 'New content' } - - subject do - patch(:update, - params: { - namespace_id: project.namespace, - project_id: project, - id: wiki_title, - wiki: { title: new_title, content: new_content } - }) - end - - context 'when page content encoding is invalid' do - it 'redirects to show' do - allow(controller).to receive(:valid_encoding?).and_return(false) - - subject - expect(response).to redirect_to_wiki(project, project_wiki.list_pages.first) - end - end - - context 'when page content encoding is valid' do - render_views - - it 'updates the page' do - subject - - wiki_page = project_wiki.list_pages(load_content: true).first - - expect(wiki_page.title).to eq new_title - expect(wiki_page.content).to eq new_content - end - end - end - - def create_page(name, content) - wiki.write_page(name, :markdown, content, commit_details(name)) - end - - def commit_details(name) - Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "created page #{name}") - end - - def destroy_page(title, dir = '') - page = wiki.page(title: title, dir: dir) - project_wiki.delete_page(page, "test commit") - end - - def redirect_to_wiki(project, page) - redirect_to(controller.project_wiki_path(project, page)) +RSpec.describe Projects::WikisController do + it_behaves_like 'wiki controller actions' do + let(:container) { create(:project, :public, :repository, namespace: user.namespace) } + let(:routing_params) { { namespace_id: container.namespace, project_id: container } } end end diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 6c00dad8bb7..8aae9ef85be 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -2,7 +2,7 @@ require('spec_helper') -describe ProjectsController do +RSpec.describe ProjectsController do include ExternalAuthorizationServiceHelpers include ProjectForksHelper @@ -41,6 +41,27 @@ describe ProjectsController do end end end + + context 'with the new_create_project_ui experiment enabled and the user is part of the control group' do + before do + stub_experiment(new_create_project_ui: true) + stub_experiment_for_user(new_create_project_ui: false) + allow_any_instance_of(described_class).to receive(:experimentation_subject_id).and_return('uuid') + end + + it 'passes the right tracking parameters to the frontend' do + get(:new) + + expect(Gon.tracking_data).to eq( + { + category: 'Manage::Import::Experiment::NewCreateProjectUi', + action: 'click_tab', + label: 'uuid', + property: 'control_group' + } + ) + end + end end end @@ -359,6 +380,15 @@ describe ProjectsController do end end end + + context 'namespace storage limit' do + let_it_be(:project) { create(:project, :public, :repository ) } + let(:namespace) { project.namespace } + + subject { get :show, params: { namespace_id: namespace, id: project } } + + it_behaves_like 'namespace storage limit alert' + end end describe 'GET edit' do @@ -1160,16 +1190,16 @@ describe ProjectsController do shared_examples 'rate limits project export endpoint' do before do - allow(::Gitlab::ApplicationRateLimiter) - .to receive(:throttled?) - .and_return(true) + allow(Gitlab::ApplicationRateLimiter) + .to receive(:increment) + .and_return(Gitlab::ApplicationRateLimiter.rate_limits["project_#{action}".to_sym][:threshold] + 1) end it 'prevents requesting project export' do post action, params: { namespace_id: project.namespace, id: project } - expect(flash[:alert]).to eq('This endpoint has been requested too many times. Try again later.') - expect(response).to have_gitlab_http_status(:found) + expect(response.body).to eq('This endpoint has been requested too many times. Try again later.') + expect(response).to have_gitlab_http_status(:too_many_requests) end end @@ -1226,7 +1256,18 @@ describe ProjectsController do end context 'when the endpoint receives requests above the limit', :clean_gitlab_redis_cache do - include_examples 'rate limits project export endpoint' + before do + allow(Gitlab::ApplicationRateLimiter) + .to receive(:increment) + .and_return(Gitlab::ApplicationRateLimiter.rate_limits[:project_download_export][:threshold] + 1) + end + + it 'prevents requesting project export' do + post action, params: { namespace_id: project.namespace, id: project } + + expect(response.body).to eq('This endpoint has been requested too many times. Try again later.') + expect(response).to have_gitlab_http_status(:too_many_requests) + end end end end diff --git a/spec/controllers/registrations/experience_levels_controller_spec.rb b/spec/controllers/registrations/experience_levels_controller_spec.rb new file mode 100644 index 00000000000..1fc728f5de8 --- /dev/null +++ b/spec/controllers/registrations/experience_levels_controller_spec.rb @@ -0,0 +1,143 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Registrations::ExperienceLevelsController do + let_it_be(:namespace) { create(:group, path: 'group-path' ) } + let_it_be(:user) { create(:user) } + + let(:params) { { namespace_path: namespace.to_param } } + + describe 'GET #show' do + subject { get :show, params: params } + + context 'with an unauthenticated user' do + it { is_expected.to have_gitlab_http_status(:redirect) } + it { is_expected.to redirect_to(new_user_session_path) } + end + + context 'with an authenticated user' do + before do + sign_in(user) + stub_experiment_for_user(onboarding_issues: true) + end + + it { is_expected.to have_gitlab_http_status(:ok) } + it { is_expected.to render_template(:show) } + + context 'when not part of the onboarding issues experiment' do + before do + stub_experiment_for_user(onboarding_issues: false) + end + + it { is_expected.to have_gitlab_http_status(:not_found) } + end + end + end + + describe 'PUT/PATCH #update' do + subject { patch :update, params: params } + + context 'with an unauthenticated user' do + it { is_expected.to have_gitlab_http_status(:redirect) } + it { is_expected.to redirect_to(new_user_session_path) } + end + + context 'with an authenticated user' do + before do + sign_in(user) + stub_experiment_for_user(onboarding_issues: true) + end + + context 'when not part of the onboarding issues experiment' do + before do + stub_experiment_for_user(onboarding_issues: false) + end + + it { is_expected.to have_gitlab_http_status(:not_found) } + end + + context 'when user is successfully updated' do + it { is_expected.to set_flash[:message].to('Welcome! You have signed up successfully.') } + + context 'when no experience_level is sent' do + before do + user.user_preference.update_attribute(:experience_level, :novice) + end + + it 'will unset the user’s experience level' do + expect { subject }.to change { user.reload.experience_level }.to(nil) + end + end + + context 'when an expected experience level is sent' do + let(:params) { super().merge(experience_level: :novice) } + + it 'sets the user’s experience level' do + expect { subject }.to change { user.reload.experience_level }.from(nil).to('novice') + end + end + + context 'when an unexpected experience level is sent' do + let(:params) { super().merge(experience_level: :nonexistent) } + + it 'raises an exception' do + expect { subject }.to raise_error(ArgumentError, "'nonexistent' is not a valid experience_level") + end + end + + context 'when a namespace_path is sent' do + it { is_expected.to have_gitlab_http_status(:redirect) } + it { is_expected.to redirect_to(group_path(namespace)) } + end + + context 'when no namespace_path is sent' do + let(:params) { super().merge(namespace_path: nil) } + + it { is_expected.to have_gitlab_http_status(:redirect) } + it { is_expected.to redirect_to(root_path) } + end + + describe 'applying the chosen level' do + context "when an 'onboarding_issues_settings' cookie does not exist" do + let(:params) { super().merge(experience_level: :novice) } + + it 'does not change the cookie' do + expect { subject }.not_to change { cookies[:onboarding_issues_settings] } + end + end + + context "when an 'onboarding_issues_settings' cookie does exist" do + before do + request.cookies[:onboarding_issues_settings] = '{}' + end + + context 'when novice' do + let(:params) { super().merge(experience_level: :novice) } + + it "adds a 'hideAdvanced' setting to the cookie" do + expect { subject }.to change { Gitlab::Json.parse(cookies[:onboarding_issues_settings])['hideAdvanced'] }.from(nil).to(true) + end + end + + context 'when experienced' do + let(:params) { super().merge(experience_level: :experienced) } + + it 'does not change the cookie' do + expect { subject }.not_to change { cookies[:onboarding_issues_settings] } + end + end + end + end + end + + context 'when user update fails' do + before do + allow_any_instance_of(User).to receive(:save).and_return(false) + end + + it { is_expected.to render_template(:show) } + end + end + end +end diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 01a9647a763..66caa58666f 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe RegistrationsController do +RSpec.describe RegistrationsController do include TermsHelper before do diff --git a/spec/controllers/repositories/git_http_controller_spec.rb b/spec/controllers/repositories/git_http_controller_spec.rb index 1a2eee5d3a9..aafb933df32 100644 --- a/spec/controllers/repositories/git_http_controller_spec.rb +++ b/spec/controllers/repositories/git_http_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Repositories::GitHttpController do +RSpec.describe Repositories::GitHttpController do include GitHttpHelpers let_it_be(:project) { create(:project, :public, :repository) } diff --git a/spec/controllers/root_controller_spec.rb b/spec/controllers/root_controller_spec.rb index 4892ff43086..9eefbcb0835 100644 --- a/spec/controllers/root_controller_spec.rb +++ b/spec/controllers/root_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe RootController do +RSpec.describe RootController do describe 'GET index' do context 'when user is not logged in' do it 'redirects to the sign-in page' do diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index 79ffa297da3..bae6bd07b67 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe SearchController do +RSpec.describe SearchController do include ExternalAuthorizationServiceHelpers let(:user) { create(:user) } @@ -211,9 +211,4 @@ describe SearchController do end.to raise_error(ActionController::ParameterMissing) end end - - describe 'GET #autocomplete' do - it_behaves_like 'when the user cannot read cross project', :autocomplete, { term: 'hello' } - it_behaves_like 'with external authorization service enabled', :autocomplete, { term: 'hello' } - end end diff --git a/spec/controllers/sent_notifications_controller_spec.rb b/spec/controllers/sent_notifications_controller_spec.rb index a0a18f66b0c..0c4a77d5926 100644 --- a/spec/controllers/sent_notifications_controller_spec.rb +++ b/spec/controllers/sent_notifications_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe SentNotificationsController do +RSpec.describe SentNotificationsController do let(:user) { create(:user) } let(:project) { create(:project, :public) } let(:private_project) { create(:project, :private) } diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index a65698a5b56..16a58112479 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe SessionsController do +RSpec.describe SessionsController do include DeviseHelpers include LdapHelpers diff --git a/spec/controllers/snippets/notes_controller_spec.rb b/spec/controllers/snippets/notes_controller_spec.rb index 0676ed05212..487635169fc 100644 --- a/spec/controllers/snippets/notes_controller_spec.rb +++ b/spec/controllers/snippets/notes_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Snippets::NotesController do +RSpec.describe Snippets::NotesController do let(:user) { create(:user) } let(:private_snippet) { create(:personal_snippet, :private) } diff --git a/spec/controllers/snippets_controller_spec.rb b/spec/controllers/snippets_controller_spec.rb index 046ee40cec2..70df1faf7dd 100644 --- a/spec/controllers/snippets_controller_spec.rb +++ b/spec/controllers/snippets_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe SnippetsController do +RSpec.describe SnippetsController do let_it_be(:user) { create(:user) } describe 'GET #index' do diff --git a/spec/controllers/uploads_controller_spec.rb b/spec/controllers/uploads_controller_spec.rb index 309a8226226..043fd97f1ad 100644 --- a/spec/controllers/uploads_controller_spec.rb +++ b/spec/controllers/uploads_controller_spec.rb @@ -1,25 +1,25 @@ # frozen_string_literal: true require 'spec_helper' -shared_examples 'content 5 min private cached with revalidation' do +RSpec.shared_examples 'content 5 min private cached with revalidation' do it 'ensures content will not be cached without revalidation' do expect(subject['Cache-Control']).to eq('max-age=300, private, must-revalidate') end end -shared_examples 'content not cached' do +RSpec.shared_examples 'content not cached' do it 'ensures content will not be cached without revalidation' do expect(subject['Cache-Control']).to eq('max-age=0, private, must-revalidate') end end -shared_examples 'content publicly cached' do +RSpec.shared_examples 'content publicly cached' do it 'ensures content is publicly cached' do expect(subject['Cache-Control']).to eq('max-age=300, public') end end -describe UploadsController do +RSpec.describe UploadsController do include WorkhorseHelpers let!(:user) { create(:user, avatar: fixture_file_upload("spec/fixtures/dk.png", "image/png")) } diff --git a/spec/controllers/user_callouts_controller_spec.rb b/spec/controllers/user_callouts_controller_spec.rb index 04f73749e1d..279f825e40f 100644 --- a/spec/controllers/user_callouts_controller_spec.rb +++ b/spec/controllers/user_callouts_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe UserCalloutsController do +RSpec.describe UserCalloutsController do let(:user) { create(:user) } before do diff --git a/spec/controllers/users/terms_controller_spec.rb b/spec/controllers/users/terms_controller_spec.rb index 99582652c39..0acc3008187 100644 --- a/spec/controllers/users/terms_controller_spec.rb +++ b/spec/controllers/users/terms_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Users::TermsController do +RSpec.describe Users::TermsController do include TermsHelper let_it_be(:user) { create(:user) } diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 2af398e143d..bec4b24484a 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe UsersController do +RSpec.describe UsersController do let(:user) { create(:user) } let(:private_user) { create(:user, private_profile: true) } let(:public_user) { create(:user) } |