diff options
Diffstat (limited to 'spec/controllers')
39 files changed, 738 insertions, 290 deletions
diff --git a/spec/controllers/abuse_reports_controller_spec.rb b/spec/controllers/abuse_reports_controller_spec.rb index da7577c371d..bab0d033056 100644 --- a/spec/controllers/abuse_reports_controller_spec.rb +++ b/spec/controllers/abuse_reports_controller_spec.rb @@ -59,7 +59,7 @@ RSpec.describe AbuseReportsController do it 'redirects back to the reported user' do post :create, params: { abuse_report: attrs } - expect(response).to redirect_to user + expect(response).to redirect_to root_path end end diff --git a/spec/controllers/admin/appearances_controller_spec.rb b/spec/controllers/admin/application_settings/appearances_controller_spec.rb index ee6a4a4c7af..cc914f3c9b8 100644 --- a/spec/controllers/admin/appearances_controller_spec.rb +++ b/spec/controllers/admin/application_settings/appearances_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Admin::AppearancesController do +RSpec.describe Admin::ApplicationSettings::AppearancesController do let(:admin) { create(:admin) } let(:header_message) { 'Header message' } let(:footer_message) { 'Footer' } diff --git a/spec/controllers/admin/groups_controller_spec.rb b/spec/controllers/admin/groups_controller_spec.rb index 8e31ef12adf..d9b7e00fd75 100644 --- a/spec/controllers/admin/groups_controller_spec.rb +++ b/spec/controllers/admin/groups_controller_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' RSpec.describe Admin::GroupsController do - let(:group) { create(:group) } - let(:project) { create(:project, namespace: group) } - let(:admin) { create(:admin) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, namespace: group) } + let_it_be(:admin) { create(:admin) } before do sign_in(admin) @@ -46,9 +46,9 @@ RSpec.describe Admin::GroupsController do end describe 'PUT #members_update' do - let(:group_user) { create(:user) } + let_it_be(:group_user) { create(:user) } - it 'adds user to members' do + it 'adds user to members', :aggregate_failures, :snowplow do put :members_update, params: { id: group, user_ids: group_user.id, @@ -58,9 +58,16 @@ RSpec.describe Admin::GroupsController do expect(controller).to set_flash.to 'Users were successfully added.' expect(response).to redirect_to(admin_group_path(group)) expect(group.users).to include group_user + expect_snowplow_event( + category: 'Members::CreateService', + action: 'create_member', + label: 'admin-group-page', + property: 'existing_user', + user: admin + ) end - it 'can add unlimited members' do + it 'can add unlimited members', :aggregate_failures do put :members_update, params: { id: group, user_ids: 1.upto(1000).to_a.join(','), @@ -71,7 +78,7 @@ RSpec.describe Admin::GroupsController do expect(response).to redirect_to(admin_group_path(group)) end - it 'adds no user to members' do + it 'adds no user to members', :aggregate_failures do put :members_update, params: { id: group, user_ids: '', diff --git a/spec/controllers/admin/integrations_controller_spec.rb b/spec/controllers/admin/integrations_controller_spec.rb index 971f2f121aa..79c39784173 100644 --- a/spec/controllers/admin/integrations_controller_spec.rb +++ b/spec/controllers/admin/integrations_controller_spec.rb @@ -93,8 +93,8 @@ RSpec.describe Admin::IntegrationsController do end it 'deletes the integration and all inheriting integrations' do - expect { subject }.to change { JiraService.for_instance.count }.by(-1) - .and change { JiraService.inherit_from_id(integration.id).count }.by(-1) + expect { subject }.to change { Integrations::Jira.for_instance.count }.by(-1) + .and change { Integrations::Jira.inherit_from_id(integration.id).count }.by(-1) end end end diff --git a/spec/controllers/admin/runners_controller_spec.rb b/spec/controllers/admin/runners_controller_spec.rb index 3984784f045..b5e7af2c012 100644 --- a/spec/controllers/admin/runners_controller_spec.rb +++ b/spec/controllers/admin/runners_controller_spec.rb @@ -12,6 +12,10 @@ RSpec.describe Admin::RunnersController do describe '#index' do render_views + before do + stub_feature_flags(runner_list_view_vue_ui: false) + end + it 'lists all runners' do get :index @@ -50,6 +54,10 @@ RSpec.describe Admin::RunnersController do describe '#show' do render_views + before do + stub_feature_flags(runner_detailed_view_vue_ui: false) + end + let_it_be(:project) { create(:project) } let_it_be(:project_two) { create(:project) } diff --git a/spec/controllers/admin/services_controller_spec.rb b/spec/controllers/admin/services_controller_spec.rb index d5ec9907b48..995282ca4bb 100644 --- a/spec/controllers/admin/services_controller_spec.rb +++ b/spec/controllers/admin/services_controller_spec.rb @@ -44,7 +44,7 @@ RSpec.describe Admin::ServicesController do describe "#update" do let(:project) { create(:project) } let!(:service_template) do - RedmineService.create!( + Integrations::Redmine.create!( project: nil, active: false, template: true, diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 722c9c322cc..da57e5f8a92 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -651,6 +651,95 @@ RSpec.describe Admin::UsersController do expect { post :update, params: params }.to change { user.reload.note }.to(note) end end + + context 'when updating credit card validation for user account' do + let(:params) do + { + id: user.to_param, + user: user_params + } + end + + shared_examples 'no credit card validation param' do + let(:user_params) { { name: 'foo' } } + + it 'does not change credit card validation' do + expect { post :update, params: params }.not_to change(Users::CreditCardValidation, :count) + end + end + + context 'when user has a credit card validation' do + before do + user.create_credit_card_validation!(credit_card_validated_at: Time.zone.now) + end + + context 'with unchecked credit card validation' do + let(:user_params) do + { credit_card_validation_attributes: { credit_card_validated_at: '0' } } + end + + it 'deletes credit_card_validation' do + expect { post :update, params: params }.to change { Users::CreditCardValidation.count }.by(-1) + end + end + + context 'with checked credit card validation' do + let(:user_params) do + { credit_card_validation_attributes: { credit_card_validated_at: '1' } } + end + + it 'does not change credit_card_validated_at' do + expect { post :update, params: params }.not_to change { user.credit_card_validated_at } + end + end + + it_behaves_like 'no credit card validation param' + end + + context 'when user does not have a credit card validation' do + context 'with checked credit card validation' do + let(:user_params) do + { credit_card_validation_attributes: { credit_card_validated_at: '1' } } + end + + it 'creates new credit card validation' do + expect { post :update, params: params }.to change { Users::CreditCardValidation.count }.by 1 + end + end + + context 'with unchecked credit card validation' do + let(:user_params) do + { credit_card_validation_attributes: { credit_card_validated_at: '0' } } + end + + it 'does not blow up' do + expect { post :update, params: params }.not_to change(Users::CreditCardValidation, :count) + end + end + + it_behaves_like 'no credit card validation param' + end + + context 'invalid parameters' do + let(:user_params) do + { credit_card_validation_attributes: { credit_card_validated_at: Time.current.iso8601 } } + end + + it_behaves_like 'no credit card validation param' + end + + context 'with non permitted params' do + let(:user_params) do + { credit_card_validation_attributes: { _destroy: true } } + end + + before do + user.create_credit_card_validation!(credit_card_validated_at: Time.zone.now) + end + + it_behaves_like 'no credit card validation param' + 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 0235d7eb95a..218aa04dd3f 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -704,7 +704,7 @@ RSpec.describe ApplicationController do get :index - expect(response.headers['Cache-Control']).to eq 'max-age=0, private, must-revalidate, no-store' + expect(response.headers['Cache-Control']).to eq 'no-store' expect(response.headers['Pragma']).to eq 'no-cache' end @@ -740,7 +740,7 @@ RSpec.describe ApplicationController do it 'sets no-cache headers', :aggregate_failures do subject - expect(response.headers['Cache-Control']).to eq 'no-cache, no-store' + expect(response.headers['Cache-Control']).to eq 'no-store' expect(response.headers['Pragma']).to eq 'no-cache' expect(response.headers['Expires']).to eq 'Fri, 01 Jan 1990 00:00:00 GMT' end diff --git a/spec/controllers/confirmations_controller_spec.rb b/spec/controllers/confirmations_controller_spec.rb index 49a39f257fe..c9a0ae981fc 100644 --- a/spec/controllers/confirmations_controller_spec.rb +++ b/spec/controllers/confirmations_controller_spec.rb @@ -12,7 +12,9 @@ RSpec.describe ConfirmationsController do describe '#show' do render_views - subject { get :show, params: { confirmation_token: confirmation_token } } + def perform_request + get :show, params: { confirmation_token: confirmation_token } + end context 'user is already confirmed' do let_it_be_with_reload(:user) { create(:user, :unconfirmed) } @@ -20,20 +22,37 @@ RSpec.describe ConfirmationsController do before do user.confirm - subject end it 'renders `new`' do + perform_request + expect(response).to render_template(:new) end it 'displays an error message' do + perform_request + expect(response.body).to include('Email was already confirmed, please try signing in') end it 'does not display the email of the user' do + perform_request + expect(response.body).not_to include(user.email) end + + it 'sets the username and caller_id in the context' do + expect(controller).to receive(:show).and_wrap_original do |m, *args| + m.call(*args) + + expect(Gitlab::ApplicationContext.current) + .to include('meta.user' => user.username, + 'meta.caller_id' => 'ConfirmationsController#show') + end + + perform_request + end end context 'user accesses the link after the expiry of confirmation token has passed' do @@ -42,39 +61,64 @@ RSpec.describe ConfirmationsController do before do allow(Devise).to receive(:confirm_within).and_return(1.day) - - travel_to(3.days.from_now) do - subject - end end it 'renders `new`' do + travel_to(3.days.from_now) { perform_request } + expect(response).to render_template(:new) end it 'displays an error message' do + travel_to(3.days.from_now) { perform_request } + expect(response.body).to include('Email needs to be confirmed within 1 day, please request a new one below') end it 'does not display the email of the user' do + travel_to(3.days.from_now) { perform_request } + expect(response.body).not_to include(user.email) end + + it 'sets the username and caller_id in the context' do + expect(controller).to receive(:show).and_wrap_original do |m, *args| + m.call(*args) + + expect(Gitlab::ApplicationContext.current) + .to include('meta.user' => user.username, + 'meta.caller_id' => 'ConfirmationsController#show') + end + + travel_to(3.days.from_now) { perform_request } + end end context 'with an invalid confirmation token' do let(:confirmation_token) { 'invalid_confirmation_token' } - before do - subject - end - it 'renders `new`' do + perform_request + expect(response).to render_template(:new) end it 'displays an error message' do + perform_request + expect(response.body).to include('Confirmation token is invalid') end + + it 'sets the the caller_id in the context' do + expect(controller).to receive(:show).and_wrap_original do |m, *args| + expect(Gitlab::ApplicationContext.current) + .to include('meta.caller_id' => 'ConfirmationsController#show') + + m.call(*args) + end + + perform_request + end end end end diff --git a/spec/controllers/dashboard/projects_controller_spec.rb b/spec/controllers/dashboard/projects_controller_spec.rb index dcec8012f03..ed8dc1eb7cb 100644 --- a/spec/controllers/dashboard/projects_controller_spec.rb +++ b/spec/controllers/dashboard/projects_controller_spec.rb @@ -156,6 +156,12 @@ RSpec.describe Dashboard::ProjectsController, :aggregate_failures do let!(:design_event) { create(:design_event, project: project) } let!(:wiki_page_event) { create(:wiki_page_event, project: project) } let!(:issue_event) { create(:closed_issue_event, project: project) } + let!(:push_event) do + create(:push_event, project: project).tap do |event| + create(:push_event_payload, event: event, ref_count: 2, ref: nil, ref_type: :tag, commit_count: 0, action: :pushed) + end + end + let(:design) { design_event.design } let(:wiki_page) { wiki_page_event.wiki_page } let(:issue) { issue_event.issue } @@ -168,9 +174,10 @@ RSpec.describe Dashboard::ProjectsController, :aggregate_failures do it 'renders all kinds of event without error' do get :index, format: :atom - expect(assigns(:events)).to include(design_event, wiki_page_event, issue_event) + expect(assigns(:events)).to include(design_event, wiki_page_event, issue_event, push_event) expect(response).to render_template('dashboard/projects/index') expect(response.body).to include( + "pushed to project", "uploaded design #{design.to_reference}", "created wiki page #{wiki_page.title}", "joined project #{project.full_name}", diff --git a/spec/controllers/groups/group_members_controller_spec.rb b/spec/controllers/groups/group_members_controller_spec.rb index b666f73110a..4b17326de09 100644 --- a/spec/controllers/groups/group_members_controller_spec.rb +++ b/spec/controllers/groups/group_members_controller_spec.rb @@ -17,7 +17,7 @@ RSpec.describe Groups::GroupMembersController do end describe 'GET index' do - it 'renders index with 200 status code' do + it 'renders index with 200 status code', :aggregate_failures do get :index, params: { group_id: group } expect(response).to have_gitlab_http_status(:ok) @@ -32,14 +32,6 @@ RSpec.describe Groups::GroupMembersController do sign_in(user) end - it 'assigns max_access_for_group' do - allow(controller).to receive(:current_user).and_return(user) - - get :index, params: { group_id: group } - - expect(user.max_access_for_group[group.id]).to eq(Gitlab::Access::OWNER) - end - it 'assigns invited members' do get :index, params: { group_id: group } @@ -126,7 +118,7 @@ RSpec.describe Groups::GroupMembersController do group.add_developer(user) end - it 'returns 403' do + it 'returns 403', :aggregate_failures do post :create, params: { group_id: group, user_ids: group_user.id, @@ -143,7 +135,7 @@ RSpec.describe Groups::GroupMembersController do group.add_owner(user) end - it 'adds user to members' do + it 'adds user to members', :aggregate_failures, :snowplow do post :create, params: { group_id: group, user_ids: group_user.id, @@ -153,9 +145,16 @@ RSpec.describe Groups::GroupMembersController do expect(controller).to set_flash.to 'Users were successfully added.' expect(response).to redirect_to(group_group_members_path(group)) expect(group.users).to include group_user + expect_snowplow_event( + category: 'Members::CreateService', + action: 'create_member', + label: 'group-members-page', + property: 'existing_user', + user: user + ) end - it 'adds no user to members' do + it 'adds no user to members', :aggregate_failures do post :create, params: { group_id: group, user_ids: '', @@ -185,7 +184,7 @@ RSpec.describe Groups::GroupMembersController do context 'when set to a date in the past' do let(:expires_at) { 2.days.ago } - it 'does not add user to members' do + it 'does not add user to members', :aggregate_failures do subject expect(flash[:alert]).to include('Expires at cannot be a date in the past') @@ -197,7 +196,7 @@ RSpec.describe Groups::GroupMembersController do context 'when set to a date in the future' do let(:expires_at) { 5.days.from_now } - it 'adds user to members' do + it 'adds user to members', :aggregate_failures do subject expect(controller).to set_flash.to 'Users were successfully added.' @@ -334,7 +333,7 @@ RSpec.describe Groups::GroupMembersController do group.add_developer(user) end - it 'returns 403' do + it 'returns 403', :aggregate_failures do delete :destroy, params: { group_id: group, id: member } expect(response).to have_gitlab_http_status(:forbidden) @@ -347,7 +346,7 @@ RSpec.describe Groups::GroupMembersController do group.add_owner(user) end - it '[HTML] removes user from members' do + it '[HTML] removes user from members', :aggregate_failures do delete :destroy, params: { group_id: group, id: member } expect(controller).to set_flash.to 'User was successfully removed from group.' @@ -356,7 +355,7 @@ RSpec.describe Groups::GroupMembersController do expect(sub_group.members).to include sub_member end - it '[HTML] removes user from members including subgroups and projects' do + it '[HTML] removes user from members including subgroups and projects', :aggregate_failures do delete :destroy, params: { group_id: group, id: member, remove_sub_memberships: true } expect(controller).to set_flash.to 'User was successfully removed from group and any subgroups and projects.' @@ -365,7 +364,7 @@ RSpec.describe Groups::GroupMembersController do expect(sub_group.members).not_to include sub_member end - it '[JS] removes user from members' do + it '[JS] removes user from members', :aggregate_failures do delete :destroy, params: { group_id: group, id: member }, xhr: true expect(response).to be_successful @@ -394,7 +393,7 @@ RSpec.describe Groups::GroupMembersController do group.add_developer(user) end - it 'removes user from members' do + it 'removes user from members', :aggregate_failures do delete :leave, params: { group_id: group } expect(controller).to set_flash.to "You left the \"#{group.name}\" group." @@ -402,7 +401,7 @@ RSpec.describe Groups::GroupMembersController do expect(group.users).not_to include user end - it 'supports json request' do + it 'supports json request', :aggregate_failures do delete :leave, params: { group_id: group }, format: :json expect(response).to have_gitlab_http_status(:ok) @@ -429,7 +428,7 @@ RSpec.describe Groups::GroupMembersController do group.request_access(user) end - it 'removes user from members' do + it 'removes user from members', :aggregate_failures do delete :leave, params: { group_id: group } expect(controller).to set_flash.to 'Your access request to the group has been withdrawn.' @@ -446,7 +445,7 @@ RSpec.describe Groups::GroupMembersController do sign_in(user) end - it 'creates a new GroupMember that is not a team member' do + it 'creates a new GroupMember that is not a team member', :aggregate_failures do post :request_access, params: { group_id: group } expect(controller).to set_flash.to 'Your request for access has been queued for review.' @@ -477,7 +476,7 @@ RSpec.describe Groups::GroupMembersController do group.add_developer(user) end - it 'returns 403' do + it 'returns 403', :aggregate_failures do post :approve_access_request, params: { group_id: group, id: member } expect(response).to have_gitlab_http_status(:forbidden) @@ -490,7 +489,7 @@ RSpec.describe Groups::GroupMembersController do group.add_owner(user) end - it 'adds user to members' do + it 'adds user to members', :aggregate_failures do post :approve_access_request, params: { group_id: group, id: member } expect(response).to redirect_to(group_group_members_path(group)) diff --git a/spec/controllers/groups/registry/repositories_controller_spec.rb b/spec/controllers/groups/registry/repositories_controller_spec.rb index 35c9a80266e..f4541eda293 100644 --- a/spec/controllers/groups/registry/repositories_controller_spec.rb +++ b/spec/controllers/groups/registry/repositories_controller_spec.rb @@ -75,6 +75,8 @@ RSpec.describe Groups::Registry::RepositoriesController do context 'json format' do let(:format) { :json } + let(:namespace) { group } + let(:snowplow_gitlab_standard_context) { { user: user, namespace: group } } it 'has the correct response schema' do subject diff --git a/spec/controllers/groups/settings/integrations_controller_spec.rb b/spec/controllers/groups/settings/integrations_controller_spec.rb index 63d99a1fab1..4f1f6dcaae4 100644 --- a/spec/controllers/groups/settings/integrations_controller_spec.rb +++ b/spec/controllers/groups/settings/integrations_controller_spec.rb @@ -124,8 +124,8 @@ RSpec.describe Groups::Settings::IntegrationsController do end it 'deletes the integration and all inheriting integrations' do - expect { subject }.to change { JiraService.for_group(group.id).count }.by(-1) - .and change { JiraService.inherit_from_id(integration.id).count }.by(-1) + expect { subject }.to change { Integrations::Jira.for_group(group.id).count }.by(-1) + .and change { Integrations::Jira.inherit_from_id(integration.id).count }.by(-1) end end end diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index f47eac7ac25..91b11cd46c5 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -651,6 +651,45 @@ RSpec.describe GroupsController, factory_default: :keep do end end + describe 'updating :prevent_sharing_groups_outside_hierarchy' do + subject do + put :update, + params: { + id: group.to_param, + group: { prevent_sharing_groups_outside_hierarchy: true } + } + end + + context 'when user is a group owner' do + before do + group.add_owner(user) + sign_in(user) + end + + it 'updates the attribute' do + expect { subject } + .to change { group.namespace_settings.reload.prevent_sharing_groups_outside_hierarchy } + .from(false) + .to(true) + + expect(response).to have_gitlab_http_status(:found) + end + end + + context 'when not a group owner' do + before do + group.add_maintainer(user) + sign_in(user) + end + + it 'does not update the attribute' do + expect { subject }.not_to change { group.namespace_settings.reload.prevent_sharing_groups_outside_hierarchy } + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + describe '#ensure_canonical_path' do before do sign_in(user) @@ -1026,14 +1065,13 @@ RSpec.describe GroupsController, factory_default: :keep do describe 'GET #download_export' do let(:admin) { create(:admin) } + let(:export_file) { fixture_file_upload('spec/fixtures/group_export.tar.gz') } before do enable_admin_mode!(admin) end context 'when there is a file available to download' do - let(:export_file) { fixture_file_upload('spec/fixtures/group_export.tar.gz') } - before do sign_in(admin) create(:import_export_upload, group: group, export_file: export_file) @@ -1046,6 +1084,22 @@ RSpec.describe GroupsController, factory_default: :keep do end end + context 'when the file is no longer present on disk' do + before do + sign_in(admin) + + create(:import_export_upload, group: group, export_file: export_file) + group.export_file.file.delete + end + + it 'returns not found' do + get :download_export, params: { id: group.to_param } + + expect(flash[:alert]).to include('file containing the export is not available yet') + expect(response).to redirect_to(edit_group_path(group)) + end + end + context 'when there is no file available to download' do before do sign_in(admin) diff --git a/spec/controllers/import/bulk_imports_controller_spec.rb b/spec/controllers/import/bulk_imports_controller_spec.rb index b450318f6f7..8f74d210667 100644 --- a/spec/controllers/import/bulk_imports_controller_spec.rb +++ b/spec/controllers/import/bulk_imports_controller_spec.rb @@ -51,7 +51,7 @@ RSpec.describe Import::BulkImportsController do end describe 'GET status' do - let(:client) { BulkImports::Clients::Http.new(uri: 'http://gitlab.example', token: 'token') } + let(:client) { BulkImports::Clients::HTTP.new(uri: 'http://gitlab.example', token: 'token') } describe 'serialized group data' do let(:client_response) do @@ -73,7 +73,7 @@ RSpec.describe Import::BulkImportsController do let(:client_params) do { top_level_only: true, - min_access_level: Gitlab::Access::MAINTAINER + min_access_level: Gitlab::Access::OWNER } end @@ -149,7 +149,7 @@ RSpec.describe Import::BulkImportsController do context 'when connection error occurs' do before do allow(controller).to receive(:client).and_return(client) - allow(client).to receive(:get).and_raise(BulkImports::Clients::Http::ConnectionError) + allow(client).to receive(:get).and_raise(BulkImports::Clients::HTTP::ConnectionError) end it 'returns 422' do diff --git a/spec/controllers/omniauth_callbacks_controller_spec.rb b/spec/controllers/omniauth_callbacks_controller_spec.rb index 4a47a4a2a53..9a142559fca 100644 --- a/spec/controllers/omniauth_callbacks_controller_spec.rb +++ b/spec/controllers/omniauth_callbacks_controller_spec.rb @@ -293,6 +293,18 @@ RSpec.describe OmniauthCallbacksController, type: :controller do expect(request.env['warden']).to be_authenticated end + + it 'sets the username and caller_id in the context' do + expect(controller).to receive(:atlassian_oauth2).and_wrap_original do |m, *args| + m.call(*args) + + expect(Gitlab::ApplicationContext.current) + .to include('meta.user' => user.username, + 'meta.caller_id' => 'OmniauthCallbacksController#atlassian_oauth2') + end + + post :atlassian_oauth2 + end end context 'for a new user' do @@ -454,6 +466,18 @@ RSpec.describe OmniauthCallbacksController, type: :controller do it 'doesn\'t link a new identity to the user' do expect { post :saml, params: { SAMLResponse: mock_saml_response } }.not_to change { user.identities.count } end + + it 'sets the username and caller_id in the context' do + expect(controller).to receive(:saml).and_wrap_original do |m, *args| + m.call(*args) + + expect(Gitlab::ApplicationContext.current) + .to include('meta.user' => user.username, + 'meta.caller_id' => 'OmniauthCallbacksController#saml') + end + + post :saml, params: { SAMLResponse: mock_saml_response } + end end end diff --git a/spec/controllers/passwords_controller_spec.rb b/spec/controllers/passwords_controller_spec.rb index e9883107456..08d68d7cec8 100644 --- a/spec/controllers/passwords_controller_spec.rb +++ b/spec/controllers/passwords_controller_spec.rb @@ -77,6 +77,18 @@ RSpec.describe PasswordsController do expect(user.password_expires_at).not_to be_nil end end + + it 'sets the username and caller_id in the context' do + expect(controller).to receive(:update).and_wrap_original do |m, *args| + m.call(*args) + + expect(Gitlab::ApplicationContext.current) + .to include('meta.user' => user.username, + 'meta.caller_id' => 'PasswordsController#update') + end + + subject + end end end end diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb index 7a72a13febe..37a633afab4 100644 --- a/spec/controllers/profiles_controller_spec.rb +++ b/spec/controllers/profiles_controller_spec.rb @@ -100,6 +100,16 @@ RSpec.describe ProfilesController, :request_store do expect(user.reload.job_title).to eq(title) expect(response).to have_gitlab_http_status(:found) end + + it 'allows updating user specified pronouns', :aggregate_failures do + pronouns = 'they/them' + sign_in(user) + + put :update, params: { user: { pronouns: pronouns } } + + expect(user.reload.pronouns).to eq(pronouns) + expect(response).to have_gitlab_http_status(:found) + end end describe 'GET audit_log' do @@ -110,7 +120,8 @@ RSpec.describe ProfilesController, :request_store do expect_snowplow_event( category: 'ProfilesController', - action: 'search_audit_event' + action: 'search_audit_event', + user: user ) end end diff --git a/spec/controllers/projects/analytics/cycle_analytics/summary_controller_spec.rb b/spec/controllers/projects/analytics/cycle_analytics/summary_controller_spec.rb new file mode 100644 index 00000000000..1832b84ab6e --- /dev/null +++ b/spec/controllers/projects/analytics/cycle_analytics/summary_controller_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Projects::Analytics::CycleAnalytics::SummaryController do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project) } + + let(:params) { { namespace_id: project.namespace.to_param, project_id: project.to_param, created_after: '2010-01-01', created_before: '2010-01-02' } } + + before do + sign_in(user) + end + + describe 'GET "show"' do + subject { get :show, params: params } + + it 'succeeds' do + project.add_reporter(user) + + subject + + expect(response).to be_successful + expect(response).to match_response_schema('analytics/cycle_analytics/summary') + end + + context 'when analytics_disabled features are disabled' do + it 'renders 404' do + project.add_reporter(user) + project.project_feature.update!(analytics_access_level: ProjectFeature::DISABLED) + + subject + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'when user is not part of the project' do + it 'renders 404' do + subject + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end +end diff --git a/spec/controllers/projects/blob_controller_spec.rb b/spec/controllers/projects/blob_controller_spec.rb index b965feee645..9493215247a 100644 --- a/spec/controllers/projects/blob_controller_spec.rb +++ b/spec/controllers/projects/blob_controller_spec.rb @@ -444,6 +444,40 @@ RSpec.describe Projects::BlobController do end end + describe 'POST preview' do + subject(:request) { post :preview, params: default_params } + + let(:user) { create(:user) } + let(:filename) { 'preview.md' } + let(:default_params) do + { + namespace_id: project.namespace, + project_id: project, + id: "#{project.default_branch}/#{filename}", + content: "Bar\n" + } + end + + before do + project.add_developer(user) + sign_in(user) + + project.repository.create_file( + project.creator, + filename, + "Foo\n", + message: 'Test', + branch_name: project.default_branch + ) + end + + it 'is successful' do + request + + expect(response).to be_successful + end + end + describe 'POST create' do let(:user) { create(:user) } let(:default_params) do diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index a99db2664a7..a00e302a64f 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -655,21 +655,6 @@ RSpec.describe Projects::BranchesController do ["feature", "improve/awesome", "merge-test", "markdown", "feature_conflict", "'test'"] ) end - - context 'branch_list_keyset_pagination is disabled' do - before do - stub_feature_flags(branch_list_keyset_pagination: false) - end - - it 'sets active and stale branches' do - expect(assigns[:active_branches].map(&:name)).not_to include( - "feature", "improve/awesome", "merge-test", "markdown", "feature_conflict", "'test'" - ) - expect(assigns[:stale_branches].map(&:name)).to eq( - ["feature", "improve/awesome", "merge-test", "markdown", "feature_conflict", "'test'"] - ) - end - end end end diff --git a/spec/controllers/projects/commit_controller_spec.rb b/spec/controllers/projects/commit_controller_spec.rb index a231b54419e..c650d145bef 100644 --- a/spec/controllers/projects/commit_controller_spec.rb +++ b/spec/controllers/projects/commit_controller_spec.rb @@ -380,18 +380,6 @@ RSpec.describe Projects::CommitController do expect(response).to have_gitlab_http_status(:not_found) end end - - context 'disable pick_into_project feature flag' do - before do - stub_feature_flags(pick_into_project: false) - end - - it 'does not cherry pick a commit from fork to upstream' do - send_request - - expect(project.commit('feature').message).not_to include(forked_project.commit.id) - end - end end end diff --git a/spec/controllers/projects/compare_controller_spec.rb b/spec/controllers/projects/compare_controller_spec.rb index 80a6d3960cd..2412b970342 100644 --- a/spec/controllers/projects/compare_controller_spec.rb +++ b/spec/controllers/projects/compare_controller_spec.rb @@ -156,7 +156,7 @@ RSpec.describe Projects::CompareController do it 'shows a flash message and redirects' do show_request - expect(flash[:alert]).to eq('Invalid branch name') + expect(flash[:alert]).to eq("Invalid branch name(s): master%' AND 2554=4423 AND '%'='") expect(response).to have_gitlab_http_status(:found) end end @@ -169,7 +169,20 @@ RSpec.describe Projects::CompareController do it 'shows a flash message and redirects' do show_request - expect(flash[:alert]).to eq('Invalid branch name') + expect(flash[:alert]).to eq("Invalid branch name(s): master%' AND 2554=4423 AND '%'='") + expect(response).to have_gitlab_http_status(:found) + end + end + + context 'when the both refs are invalid' do + let(:from_project_id) { nil } + let(:from_ref) { "master%' AND 2554=4423 AND '%'='" } + let(:to_ref) { "improve%' =,awesome" } + + it 'shows a flash message and redirects' do + show_request + + expect(flash[:alert]).to eq("Invalid branch name(s): improve%' =,awesome, master%' AND 2554=4423 AND '%'='") expect(response).to have_gitlab_http_status(:found) end end diff --git a/spec/controllers/projects/feature_flags_controller_spec.rb b/spec/controllers/projects/feature_flags_controller_spec.rb index cd7d1ea0e8a..f809dd31b3b 100644 --- a/spec/controllers/projects/feature_flags_controller_spec.rb +++ b/spec/controllers/projects/feature_flags_controller_spec.rb @@ -154,60 +154,6 @@ RSpec.describe Projects::FeatureFlagsController do end end - context 'when feature flags have additional scopes' do - let!(:feature_flag_active_scope) do - create(:operations_feature_flag_scope, - feature_flag: feature_flag_active, - environment_scope: 'production', - active: false) - end - - let!(:feature_flag_inactive_scope) do - create(:operations_feature_flag_scope, - feature_flag: feature_flag_inactive, - environment_scope: 'staging', - active: false) - end - - it 'returns a correct summary' do - subject - - expect(json_response['count']['all']).to eq(2) - expect(json_response['count']['enabled']).to eq(1) - expect(json_response['count']['disabled']).to eq(1) - end - - it 'recognizes feature flag 1 as active' do - subject - - expect(json_response['feature_flags'].first['active']).to be_truthy - end - - it 'recognizes feature flag 2 as inactive' do - subject - - expect(json_response['feature_flags'].second['active']).to be_falsy - end - - it 'has ordered scopes' do - subject - - expect(json_response['feature_flags'][0]['scopes'][0]['id']) - .to be < json_response['feature_flags'][0]['scopes'][1]['id'] - expect(json_response['feature_flags'][1]['scopes'][0]['id']) - .to be < json_response['feature_flags'][1]['scopes'][1]['id'] - end - - it 'does not have N+1 problem' do - recorded = ActiveRecord::QueryRecorder.new { subject } - - related_count = recorded.log - .count { |query| query.include?('operations_feature_flag') } - - expect(related_count).to be_within(5).of(2) - end - end - context 'with version 1 and 2 feature flags' do let!(:new_version_feature_flag) do create(:operations_feature_flag, :new_version_flag, project: project, name: 'feature_flag_c') @@ -235,7 +181,7 @@ RSpec.describe Projects::FeatureFlagsController do subject { get(:show, params: params, format: :json) } let!(:feature_flag) do - create(:operations_feature_flag, project: project) + create(:operations_feature_flag, :legacy_flag, project: project) end let(:params) do @@ -371,6 +317,42 @@ RSpec.describe Projects::FeatureFlagsController do end end + describe 'GET edit' do + subject { get(:edit, params: params) } + + context 'with legacy flags' do + let!(:feature_flag) { create(:operations_feature_flag, :legacy_flag, project: project) } + + let(:params) do + { + namespace_id: project.namespace, + project_id: project, + iid: feature_flag.iid + } + end + + it 'returns not found' do + is_expected.to have_gitlab_http_status(:not_found) + end + end + + context 'with new version flags' do + let!(:feature_flag) { create(:operations_feature_flag, project: project) } + + let(:params) do + { + namespace_id: project.namespace, + project_id: project, + iid: feature_flag.iid + } + end + + it 'returns successfully' do + is_expected.to have_gitlab_http_status(:ok) + end + end + end + describe 'POST create.json' do subject { post(:create, params: params, format: :json) } @@ -762,7 +744,7 @@ RSpec.describe Projects::FeatureFlagsController do describe 'DELETE destroy.json' do subject { delete(:destroy, params: params, format: :json) } - let!(:feature_flag) { create(:operations_feature_flag, project: project) } + let!(:feature_flag) { create(:operations_feature_flag, :legacy_flag, project: project) } let(:params) do { diff --git a/spec/controllers/projects/feature_flags_user_lists_controller_spec.rb b/spec/controllers/projects/feature_flags_user_lists_controller_spec.rb index e0d1d3765b2..32817f048e6 100644 --- a/spec/controllers/projects/feature_flags_user_lists_controller_spec.rb +++ b/spec/controllers/projects/feature_flags_user_lists_controller_spec.rb @@ -16,6 +16,39 @@ RSpec.describe Projects::FeatureFlagsUserListsController do { namespace_id: project.namespace, project_id: project }.merge(extra_params) end + describe 'GET #index' do + it 'redirects when the user is unauthenticated' do + get(:index, params: request_params) + + expect(response).to redirect_to(new_user_session_path) + end + + it 'returns not found if the user does not belong to the project' do + user = create(:user) + sign_in(user) + + get(:index, params: request_params) + + expect(response).to have_gitlab_http_status(:not_found) + end + + it 'returns not found for a reporter' do + sign_in(reporter) + + get(:index, params: request_params) + + expect(response).to have_gitlab_http_status(:not_found) + end + + it 'renders the new page for a developer' do + sign_in(developer) + + get(:index, params: request_params) + + expect(response).to have_gitlab_http_status(:ok) + end + end + describe 'GET #new' do it 'redirects when the user is unauthenticated' do get(:new, params: request_params) diff --git a/spec/controllers/projects/forks_controller_spec.rb b/spec/controllers/projects/forks_controller_spec.rb index 8ca3009e0c7..e53e53980b5 100644 --- a/spec/controllers/projects/forks_controller_spec.rb +++ b/spec/controllers/projects/forks_controller_spec.rb @@ -195,6 +195,25 @@ RSpec.describe Projects::ForksController do expect(json_response['namespaces'].length).to eq(1) expect(json_response['namespaces'][0]['id']).to eq(group.id) end + + context 'N+1 queries' do + before do + create(:fork_network, root_project: project) + end + + it 'avoids N+1 queries' do + do_request = -> { get :new, format: format, params: { namespace_id: project.namespace, project_id: project } } + + # warm up + do_request.call + + control = ActiveRecord::QueryRecorder.new { do_request.call } + + create(:group, :public).add_owner(user) + + expect { do_request.call }.not_to exceed_query_limit(control) + end + end end end diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index 059e7884d55..7569a18baeb 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -310,7 +310,7 @@ RSpec.describe Projects::IssuesController do context 'external issue tracker' do let!(:service) do - create(:custom_issue_tracker_service, project: project, new_issue_url: 'http://test.com') + create(:custom_issue_tracker_integration, project: project, new_issue_url: 'http://test.com') end before do diff --git a/spec/controllers/projects/mattermosts_controller_spec.rb b/spec/controllers/projects/mattermosts_controller_spec.rb index 10bcee28f71..edec8c3e9c6 100644 --- a/spec/controllers/projects/mattermosts_controller_spec.rb +++ b/spec/controllers/projects/mattermosts_controller_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Projects::MattermostsController do describe 'GET #new' do before do - allow_next_instance_of(MattermostSlashCommandsService) do |instance| + allow_next_instance_of(Integrations::MattermostSlashCommands) do |instance| allow(instance).to receive(:list_teams).and_return([]) end end @@ -43,7 +43,7 @@ RSpec.describe Projects::MattermostsController do context 'no request can be made to mattermost' do it 'shows the error' do - allow_next_instance_of(MattermostSlashCommandsService) do |instance| + allow_next_instance_of(Integrations::MattermostSlashCommands) do |instance| allow(instance).to receive(:configure).and_return([false, "error message"]) end @@ -53,7 +53,7 @@ RSpec.describe Projects::MattermostsController do context 'the request is succesull' do before do - allow_next_instance_of(Mattermost::Command) do |instance| + allow_next_instance_of(::Mattermost::Command) do |instance| allow(instance).to receive(:create).and_return('token') end end diff --git a/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb b/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb index c2cc3d10ea0..e07b7e4586a 100644 --- a/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb @@ -17,8 +17,31 @@ RSpec.describe Projects::MergeRequests::ConflictsController do end describe 'GET show' do + context 'when the request is html' do + before do + allow(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) + .to receive(:track_loading_conflict_ui_action) + + get :show, + params: { + namespace_id: merge_request_with_conflicts.project.namespace.to_param, + project_id: merge_request_with_conflicts.project, + id: merge_request_with_conflicts.iid + }, + format: 'html' + end + + it 'does tracks the resolve call' do + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) + .to have_received(:track_loading_conflict_ui_action).with(user: user) + end + end + context 'when the conflicts cannot be resolved in the UI' do before do + allow(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) + .to receive(:track_loading_conflict_ui_action) + allow(Gitlab::Git::Conflict::Parser).to receive(:parse) .and_raise(Gitlab::Git::Conflict::Parser::UnmergeableFile) @@ -38,6 +61,11 @@ RSpec.describe Projects::MergeRequests::ConflictsController do it 'returns JSON with a message' do expect(json_response.keys).to contain_exactly('message', 'type') end + + it 'does not track the resolve call' do + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) + .not_to have_received(:track_loading_conflict_ui_action).with(user: user) + end end context 'with valid conflicts' do @@ -145,20 +173,19 @@ RSpec.describe Projects::MergeRequests::ConflictsController do conflict_for_path(path) end - it 'returns a 200 status code' do - expect(response).to have_gitlab_http_status(:ok) - end - - it 'returns the file in JSON format' do + it 'returns a 200 and the file in JSON format' do content = MergeRequests::Conflicts::ListService.new(merge_request_with_conflicts) .file_for_path(path, path) .content - expect(json_response).to include('old_path' => path, - 'new_path' => path, - 'blob_icon' => 'doc-text', - 'blob_path' => a_string_ending_with(path), - 'content' => content) + aggregate_failures do + expect(response).to have_gitlab_http_status(:ok) + expect(json_response).to include('old_path' => path, + 'new_path' => path, + 'blob_icon' => 'doc-text', + 'blob_path' => a_string_ending_with(path), + 'content' => content) + end end end end @@ -166,6 +193,11 @@ RSpec.describe Projects::MergeRequests::ConflictsController do context 'POST resolve_conflicts' do let!(:original_head_sha) { merge_request_with_conflicts.diff_head_sha } + before do + allow(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) + .to receive(:track_resolve_conflict_action) + end + def resolve_conflicts(files) post :resolve_conflicts, params: { @@ -201,13 +233,16 @@ RSpec.describe Projects::MergeRequests::ConflictsController do resolve_conflicts(resolved_files) end - it 'creates a new commit on the branch' do - expect(original_head_sha).not_to eq(merge_request_with_conflicts.source_branch_head.sha) - expect(merge_request_with_conflicts.source_branch_head.message).to include('Commit message') - end + it 'handles the success case' do + aggregate_failures do + # creates a new commit on the branch + expect(original_head_sha).not_to eq(merge_request_with_conflicts.source_branch_head.sha) + expect(merge_request_with_conflicts.source_branch_head.message).to include('Commit message') - it 'returns an OK response' do - expect(response).to have_gitlab_http_status(:ok) + expect(response).to have_gitlab_http_status(:ok) + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) + .to have_received(:track_resolve_conflict_action).with(user: user) + end end end @@ -232,16 +267,17 @@ RSpec.describe Projects::MergeRequests::ConflictsController do resolve_conflicts(resolved_files) end - it 'returns a 400 error' do - expect(response).to have_gitlab_http_status(:bad_request) - end - - it 'has a message with the name of the first missing section' do - expect(json_response['message']).to include('6eb14e00385d2fb284765eb1cd8d420d33d63fc9_21_21') - end + it 'handles the error case' do + aggregate_failures do + # has a message with the name of the first missing section + expect(json_response['message']).to include('6eb14e00385d2fb284765eb1cd8d420d33d63fc9_21_21') + # does not create a new commit + expect(original_head_sha).to eq(merge_request_with_conflicts.source_branch_head.sha) - it 'does not create a new commit' do - expect(original_head_sha).to eq(merge_request_with_conflicts.source_branch_head.sha) + expect(response).to have_gitlab_http_status(:bad_request) + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) + .to have_received(:track_resolve_conflict_action).with(user: user) + end end end @@ -262,16 +298,17 @@ RSpec.describe Projects::MergeRequests::ConflictsController do resolve_conflicts(resolved_files) end - it 'returns a 400 error' do - expect(response).to have_gitlab_http_status(:bad_request) - end + it 'handles the error case' do + aggregate_failures do + # has a message with the name of the missing file + expect(json_response['message']).to include('files/ruby/popen.rb') + # does not create a new commit + expect(original_head_sha).to eq(merge_request_with_conflicts.source_branch_head.sha) - it 'has a message with the name of the missing file' do - expect(json_response['message']).to include('files/ruby/popen.rb') - end - - it 'does not create a new commit' do - expect(original_head_sha).to eq(merge_request_with_conflicts.source_branch_head.sha) + expect(response).to have_gitlab_http_status(:bad_request) + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) + .to have_received(:track_resolve_conflict_action).with(user: user) + end end end @@ -300,16 +337,17 @@ RSpec.describe Projects::MergeRequests::ConflictsController do resolve_conflicts(resolved_files) end - it 'returns a 400 error' do - expect(response).to have_gitlab_http_status(:bad_request) - end - - it 'has a message with the path of the problem file' do - expect(json_response['message']).to include('files/ruby/popen.rb') - end + it 'handles the error case' do + aggregate_failures do + # has a message with the path of the problem file + expect(json_response['message']).to include('files/ruby/popen.rb') + # does not create a new commit + expect(original_head_sha).to eq(merge_request_with_conflicts.source_branch_head.sha) - it 'does not create a new commit' do - expect(original_head_sha).to eq(merge_request_with_conflicts.source_branch_head.sha) + expect(response).to have_gitlab_http_status(:bad_request) + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) + .to have_received(:track_resolve_conflict_action).with(user: user) + end end end end diff --git a/spec/controllers/projects/packages/infrastructure_registry_controller_spec.rb b/spec/controllers/projects/packages/infrastructure_registry_controller_spec.rb new file mode 100644 index 00000000000..dc5a022eb7b --- /dev/null +++ b/spec/controllers/projects/packages/infrastructure_registry_controller_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Projects::Packages::InfrastructureRegistryController do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :private) } + + let(:params) { { namespace_id: project.namespace, project_id: project } } + + before do + sign_in(user) + project.add_maintainer(user) + end + + describe 'GET #index' do + subject { get :index, params: params, format: :html } + + it_behaves_like 'returning response status', :ok + + context 'when the feature is disabled' do + before do + stub_feature_flags(infrastructure_registry_page: false) + end + + it_behaves_like 'returning response status', :not_found + end + end + + describe 'GET #show' do + let_it_be(:terraform_module) { create(:terraform_module_package, project: project) } + + subject { get :show, params: params.merge(id: terraform_module.id), format: :html } + + it_behaves_like 'returning response status', :ok + + context 'when the feature is disabled' do + before do + stub_feature_flags(infrastructure_registry_page: false) + end + + it_behaves_like 'returning response status', :not_found + end + end +end diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index 0e6b5e84d85..a80c5fa82f6 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -274,30 +274,26 @@ RSpec.describe Projects::PipelinesController do end describe 'GET #index' do - context 'pipeline_empty_state_templates experiment' do - before do - stub_application_setting(auto_devops_enabled: false) - end + before do + stub_application_setting(auto_devops_enabled: false) + end - it 'tracks the view', :experiment do - expect(experiment(:pipeline_empty_state_templates)) - .to track(:view, value: project.namespace_id) - .with_context(actor: user) - .on_next_instance + def action + get :index, params: { namespace_id: project.namespace, project_id: project } + end - get :index, params: { namespace_id: project.namespace, project_id: project } - end + subject { project.namespace } + + context 'pipeline_empty_state_templates experiment' do + it_behaves_like 'tracks assignment and records the subject', :pipeline_empty_state_templates, :namespace end context 'code_quality_walkthrough experiment' do - it 'tracks the view', :experiment do - expect(experiment(:code_quality_walkthrough)) - .to track(:view, property: project.root_ancestor.id.to_s) - .with_context(namespace: project.root_ancestor) - .on_next_instance + it_behaves_like 'tracks assignment and records the subject', :code_quality_walkthrough, :namespace + end - get :index, params: { namespace_id: project.namespace, project_id: project } - end + context 'ci_runner_templates experiment' do + it_behaves_like 'tracks assignment and records the subject', :ci_runner_templates, :namespace end end @@ -878,19 +874,6 @@ RSpec.describe Projects::PipelinesController do expect(::Ci::RetryPipelineWorker).to have_received(:perform_async).with(pipeline.id, user.id) end - context 'when feature flag is disabled' do - before do - stub_feature_flags(background_pipeline_retry_endpoint: false) - end - - it 'retries the pipeline without returning any content' do - post_retry - - expect(response).to have_gitlab_http_status(:no_content) - expect(build.reload).to be_retried - end - end - context 'when builds are disabled' do let(:feature) { ProjectFeature::DISABLED } diff --git a/spec/controllers/projects/project_members_controller_spec.rb b/spec/controllers/projects/project_members_controller_spec.rb index bb817fc94b2..9ed43a251a2 100644 --- a/spec/controllers/projects/project_members_controller_spec.rb +++ b/spec/controllers/projects/project_members_controller_spec.rb @@ -3,9 +3,9 @@ require('spec_helper') RSpec.describe Projects::ProjectMembersController do - let(:user) { create(:user) } - let(:group) { create(:group, :public) } - let(:project) { create(:project, :public) } + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group, :public) } + let_it_be(:project, reload: true) { create(:project, :public) } before do travel_to DateTime.new(2019, 4, 1) @@ -24,8 +24,8 @@ RSpec.describe Projects::ProjectMembersController do context 'project members' do context 'when project belongs to group' do - let(:user_in_group) { create(:user) } - let(:project_in_group) { create(:project, :public, group: group) } + let_it_be(:user_in_group) { create(:user) } + let_it_be(:project_in_group) { create(:project, :public, group: group) } before do group.add_owner(user_in_group) @@ -69,7 +69,7 @@ RSpec.describe Projects::ProjectMembersController do end context 'group links' do - let!(:project_group_link) { create(:project_group_link, project: project, group: group) } + let_it_be(:project_group_link) { create(:project_group_link, project: project, group: group) } it 'lists group links' do get :index, params: { namespace_id: project.namespace, project_id: project } @@ -90,7 +90,7 @@ RSpec.describe Projects::ProjectMembersController do end context 'invited members' do - let!(:invited_member) { create(:project_member, :invited, project: project) } + let_it_be(:invited_member) { create(:project_member, :invited, project: project) } before do project.add_maintainer(user) @@ -123,7 +123,7 @@ RSpec.describe Projects::ProjectMembersController do end context 'access requests' do - let(:access_requester_user) { create(:user) } + let_it_be(:access_requester_user) { create(:user) } before do project.request_access(access_requester_user) @@ -158,7 +158,7 @@ RSpec.describe Projects::ProjectMembersController do end describe 'POST create' do - let(:project_user) { create(:user) } + let_it_be(:project_user) { create(:user) } before do sign_in(user) @@ -169,7 +169,7 @@ RSpec.describe Projects::ProjectMembersController do project.add_developer(user) end - it 'returns 404' do + it 'returns 404', :aggregate_failures do post :create, params: { namespace_id: project.namespace, project_id: project, @@ -187,11 +187,7 @@ RSpec.describe Projects::ProjectMembersController do project.add_maintainer(user) end - it 'adds user to members' do - expect_next_instance_of(Members::CreateService) do |instance| - expect(instance).to receive(:execute).and_return(status: :success) - end - + it 'adds user to members', :aggregate_failures, :snowplow do post :create, params: { namespace_id: project.namespace, project_id: project, @@ -201,9 +197,17 @@ RSpec.describe Projects::ProjectMembersController do expect(controller).to set_flash.to 'Users were successfully added.' expect(response).to redirect_to(project_project_members_path(project)) + expect(project.users).to include project_user + expect_snowplow_event( + category: 'Members::CreateService', + action: 'create_member', + label: 'project-members-page', + property: 'existing_user', + user: user + ) end - it 'adds no user to members' do + it 'adds no user to members', :aggregate_failures do expect_next_instance_of(Members::CreateService) do |instance| expect(instance).to receive(:execute).and_return(status: :failure, message: 'Message') end @@ -230,7 +234,7 @@ RSpec.describe Projects::ProjectMembersController do unrelated_project.add_maintainer(project_bot) end - it 'returns error' do + it 'returns error', :aggregate_failures do post :create, params: { namespace_id: project.namespace, project_id: project, @@ -261,7 +265,7 @@ RSpec.describe Projects::ProjectMembersController do context 'when set to a date in the past' do let(:expires_at) { 2.days.ago } - it 'does not add user to members' do + it 'does not add user to members', :aggregate_failures do subject expect(flash[:alert]).to include('Expires at cannot be a date in the past') @@ -273,7 +277,7 @@ RSpec.describe Projects::ProjectMembersController do context 'when set to a date in the future' do let(:expires_at) { 5.days.from_now } - it 'adds user to members' do + it 'adds user to members', :aggregate_failures do subject expect(controller).to set_flash.to 'Users were successfully added.' @@ -285,7 +289,7 @@ RSpec.describe Projects::ProjectMembersController do end describe 'PUT update' do - let(:requester) { create(:project_member, :access_request, project: project) } + let_it_be(:requester) { create(:project_member, :access_request, project: project) } before do project.add_maintainer(user) @@ -393,7 +397,7 @@ RSpec.describe Projects::ProjectMembersController do end describe 'DELETE destroy' do - let(:member) { create(:project_member, :developer, project: project) } + let_it_be(:member) { create(:project_member, :developer, project: project) } before do sign_in(user) @@ -417,7 +421,7 @@ RSpec.describe Projects::ProjectMembersController do project.add_developer(user) end - it 'returns 404' do + it 'returns 404', :aggregate_failures do delete :destroy, params: { namespace_id: project.namespace, project_id: project, @@ -434,7 +438,7 @@ RSpec.describe Projects::ProjectMembersController do project.add_maintainer(user) end - it '[HTML] removes user from members' do + it '[HTML] removes user from members', :aggregate_failures do delete :destroy, params: { namespace_id: project.namespace, project_id: project, @@ -447,7 +451,7 @@ RSpec.describe Projects::ProjectMembersController do expect(project.members).not_to include member end - it '[JS] removes user from members' do + it '[JS] removes user from members', :aggregate_failures do delete :destroy, params: { namespace_id: project.namespace, project_id: project, @@ -483,7 +487,7 @@ RSpec.describe Projects::ProjectMembersController do project.add_developer(user) end - it 'removes user from members' do + it 'removes user from members', :aggregate_failures do delete :leave, params: { namespace_id: project.namespace, project_id: project @@ -517,7 +521,7 @@ RSpec.describe Projects::ProjectMembersController do project.request_access(user) end - it 'removes user from members' do + it 'removes user from members', :aggregate_failures do delete :leave, params: { namespace_id: project.namespace, project_id: project @@ -537,7 +541,7 @@ RSpec.describe Projects::ProjectMembersController do sign_in(user) end - it 'creates a new ProjectMember that is not a team member' do + it 'creates a new ProjectMember that is not a team member', :aggregate_failures do post :request_access, params: { namespace_id: project.namespace, project_id: project @@ -553,7 +557,7 @@ RSpec.describe Projects::ProjectMembersController do end describe 'POST approve' do - let(:member) { create(:project_member, :access_request, project: project) } + let_it_be(:member) { create(:project_member, :access_request, project: project) } before do sign_in(user) @@ -577,7 +581,7 @@ RSpec.describe Projects::ProjectMembersController do project.add_developer(user) end - it 'returns 404' do + it 'returns 404', :aggregate_failures do post :approve_access_request, params: { namespace_id: project.namespace, project_id: project, @@ -594,7 +598,7 @@ RSpec.describe Projects::ProjectMembersController do project.add_maintainer(user) end - it 'adds user to members' do + it 'adds user to members', :aggregate_failures do post :approve_access_request, params: { namespace_id: project.namespace, project_id: project, @@ -611,8 +615,8 @@ RSpec.describe Projects::ProjectMembersController do end describe 'POST apply_import' do - let(:another_project) { create(:project, :private) } - let(:member) { create(:user) } + let_it_be(:another_project) { create(:project, :private) } + let_it_be(:member) { create(:user) } before do project.add_maintainer(user) @@ -637,7 +641,7 @@ RSpec.describe Projects::ProjectMembersController do include_context 'import applied' - it 'imports source project members' do + it 'imports source project members', :aggregate_failures do expect(project.team_members).to include member expect(controller).to set_flash.to 'Successfully imported' expect(response).to redirect_to( @@ -660,7 +664,7 @@ RSpec.describe Projects::ProjectMembersController do end describe 'POST create' do - let(:stranger) { create(:user) } + let_it_be(:stranger) { create(:user) } context 'when creating owner' do before do @@ -700,7 +704,7 @@ RSpec.describe Projects::ProjectMembersController do end describe 'POST resend_invite' do - let(:member) { create(:project_member, project: project) } + let_it_be(:member) { create(:project_member, project: project) } before do project.add_maintainer(user) diff --git a/spec/controllers/projects/service_hook_logs_controller_spec.rb b/spec/controllers/projects/service_hook_logs_controller_spec.rb index 97fb31f0546..040e59fc822 100644 --- a/spec/controllers/projects/service_hook_logs_controller_spec.rb +++ b/spec/controllers/projects/service_hook_logs_controller_spec.rb @@ -5,13 +5,13 @@ require 'spec_helper' RSpec.describe Projects::ServiceHookLogsController do let(:project) { create(:project, :repository) } let(:user) { create(:user) } - let(:service) { create(:drone_ci_service, project: project) } - let(:log) { create(:web_hook_log, web_hook: service.service_hook) } + let(:integration) { create(:drone_ci_integration, project: project) } + let(:log) { create(:web_hook_log, web_hook: integration.service_hook) } let(:log_params) do { namespace_id: project.namespace, project_id: project, - service_id: service.to_param, + service_id: integration.to_param, id: log.id } end @@ -35,7 +35,7 @@ RSpec.describe Projects::ServiceHookLogsController do it 'executes the hook and redirects to the service form' do expect_any_instance_of(ServiceHook).to receive(:execute) expect_any_instance_of(described_class).to receive(:set_hook_execution_notice) - expect(subject).to redirect_to(edit_project_service_path(project, service)) + expect(subject).to redirect_to(edit_project_service_path(project, integration)) end end end diff --git a/spec/controllers/projects/services_controller_spec.rb b/spec/controllers/projects/services_controller_spec.rb index d8fb3b226ed..f8474ab1082 100644 --- a/spec/controllers/projects/services_controller_spec.rb +++ b/spec/controllers/projects/services_controller_spec.rb @@ -47,7 +47,7 @@ RSpec.describe Projects::ServicesController do let(:service) { project.create_microsoft_teams_service(webhook: 'http://webhook.com') } it 'returns success' do - allow_any_instance_of(MicrosoftTeams::Notifier).to receive(:ping).and_return(true) + allow_any_instance_of(::MicrosoftTeams::Notifier).to receive(:ping).and_return(true) put :test, params: project_params @@ -95,7 +95,7 @@ RSpec.describe Projects::ServicesController do expect(response).to be_successful expect(json_response).to be_empty - expect(BuildkiteService.first).to be_present + expect(Integrations::Buildkite.first).to be_present end it 'creates the ServiceHook object' do @@ -103,7 +103,7 @@ RSpec.describe Projects::ServicesController do expect(response).to be_successful expect(json_response).to be_empty - expect(BuildkiteService.first.service_hook).to be_present + expect(Integrations::Buildkite.first.service_hook).to be_present end def do_put @@ -145,7 +145,7 @@ RSpec.describe Projects::ServicesController do end it 'returns an error response when a network exception is raised' do - expect_next(SlackService).to receive(:test).and_raise(Errno::ECONNREFUSED) + expect_next(Integrations::Slack).to receive(:test).and_raise(Errno::ECONNREFUSED) put :test, params: project_params diff --git a/spec/controllers/projects/settings/operations_controller_spec.rb b/spec/controllers/projects/settings/operations_controller_spec.rb index d2934ec4e97..7ef5371f2b5 100644 --- a/spec/controllers/projects/settings/operations_controller_spec.rb +++ b/spec/controllers/projects/settings/operations_controller_spec.rb @@ -509,7 +509,10 @@ RSpec.describe Projects::Settings::OperationsController do it 'tracks an event' do expect_snowplow_event( category: 'project:operations:tracing', - action: 'external_url_populated' + action: 'external_url_populated', + user: user, + project: project, + namespace: project.namespace ) end end diff --git a/spec/controllers/projects/templates_controller_spec.rb b/spec/controllers/projects/templates_controller_spec.rb index bd299efb5b5..da381357bda 100644 --- a/spec/controllers/projects/templates_controller_spec.rb +++ b/spec/controllers/projects/templates_controller_spec.rb @@ -160,28 +160,12 @@ RSpec.describe Projects::TemplatesController do end shared_examples 'template names request' do - context 'when feature flag enabled' do - it 'returns the template names', :aggregate_failures do - get(:names, params: { namespace_id: project.namespace, template_type: template_type, project_id: project }, format: :json) - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response['Project Templates'].size).to eq(2) - expect(json_response['Project Templates'].map { |x| x.slice('name') }).to match(expected_template_names) - end - end - - context 'when feature flag disabled' do - before do - stub_feature_flags(inherited_issuable_templates: false) - end - - it 'returns the template names', :aggregate_failures do - get(:names, params: { namespace_id: project.namespace, template_type: template_type, project_id: project }, format: :json) + it 'returns the template names', :aggregate_failures do + get(:names, params: { namespace_id: project.namespace, template_type: template_type, project_id: project }, format: :json) - expect(response).to have_gitlab_http_status(:ok) - expect(json_response.size).to eq(2) - expect(json_response.map { |x| x.slice('name') }).to match(expected_template_names) - end + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['Project Templates'].size).to eq(2) + expect(json_response['Project Templates'].map { |x| x.slice('name') }).to match(expected_template_names) end it 'fails for user with no access' do diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index fdc687496b7..ce229fb861a 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -7,7 +7,7 @@ RSpec.describe ProjectsController do include ProjectForksHelper using RSpec::Parameterized::TableSyntax - let_it_be(:project, reload: true) { create(:project, service_desk_enabled: false) } + let_it_be(:project, reload: true) { create(:project, :with_export, service_desk_enabled: false) } let_it_be(:public_project) { create(:project, :public) } let_it_be(:user) { create(:user) } @@ -243,9 +243,8 @@ RSpec.describe ProjectsController do get :show, params: { namespace_id: empty_project.namespace, id: empty_project } end - it "renders the empty project view and records the experiment user", :aggregate_failures do + it "renders the empty project view" do expect(response).to render_template('empty') - expect(controller).to have_received(:record_experiment_user).with(:invite_members_empty_project_version_a) end end end @@ -1350,7 +1349,7 @@ RSpec.describe ProjectsController do end end - describe '#download_export' do + describe '#download_export', :clean_gitlab_redis_cache do let(:action) { :download_export } context 'object storage enabled' do @@ -1362,6 +1361,17 @@ RSpec.describe ProjectsController do end end + context 'when project export file is absent' do + it 'alerts the user and returns 302' do + project.export_file.file.delete + + get action, params: { namespace_id: project.namespace, id: project } + + expect(flash[:alert]).to include('file containing the export is not available yet') + expect(response).to have_gitlab_http_status(:found) + end + end + context 'when project export is disabled' do before do stub_application_setting(project_export_enabled?: false) diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index ff73c0aafe8..81486c310d4 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -434,6 +434,18 @@ RSpec.describe RegistrationsController do expect(User.last.last_name).to eq(base_user_params[:last_name]) expect(User.last.name).to eq("#{base_user_params[:first_name]} #{base_user_params[:last_name]}") end + + it 'sets the username and caller_id in the context' do + expect(controller).to receive(:create).and_wrap_original do |m, *args| + m.call(*args) + + expect(Gitlab::ApplicationContext.current) + .to include('meta.user' => base_user_params[:username], + 'meta.caller_id' => 'RegistrationsController#create') + end + + subject + end end describe '#destroy' do @@ -525,5 +537,17 @@ RSpec.describe RegistrationsController do end end end + + it 'sets the username and caller_id in the context' do + expect(controller).to receive(:destroy).and_wrap_original do |m, *args| + m.call(*args) + + expect(Gitlab::ApplicationContext.current) + .to include('meta.user' => user.username, + 'meta.caller_id' => 'RegistrationsController#destroy') + end + + post :destroy + end end end diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index 32ac83847aa..3a2986f6cbe 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -258,7 +258,7 @@ RSpec.describe SearchController do expect(response).to have_gitlab_http_status(:ok) - expect(response.headers['Cache-Control']).to include('max-age=60, private') + expect(response.headers['Cache-Control']).to eq('no-store') end end |