diff options
Diffstat (limited to 'spec/controllers')
37 files changed, 470 insertions, 680 deletions
diff --git a/spec/controllers/admin/groups_controller_spec.rb b/spec/controllers/admin/groups_controller_spec.rb index c534cf14327..6596d788e98 100644 --- a/spec/controllers/admin/groups_controller_spec.rb +++ b/spec/controllers/admin/groups_controller_spec.rb @@ -11,6 +11,96 @@ RSpec.describe Admin::GroupsController do sign_in(admin) end + describe 'GET #index' do + let!(:group_2) { create(:group, name: 'Ygroup') } + let!(:group_3) { create(:group, name: 'Jgroup', created_at: 2.days.ago, updated_at: 1.day.ago) } + + render_views + + it 'lists available groups' do + get :index + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:index) + expect(assigns(:groups)).to eq([group, group_2, group_3]) + end + + it 'renders a correct list of sort by options' do + get :index + + html_rendered = Nokogiri::HTML(response.body) + sort_options = Gitlab::Json.parse(html_rendered.css('div.dropdown')[0]['data-items']) + + expect(response).to render_template('shared/groups/_dropdown') + + expect(sort_options.size).to eq(7) + expect(sort_options[0]['value']).to eq('name_asc') + expect(sort_options[0]['text']).to eq(s_('SortOptions|Name')) + + expect(sort_options[1]['value']).to eq('name_desc') + expect(sort_options[1]['text']).to eq(s_('SortOptions|Name, descending')) + + expect(sort_options[2]['value']).to eq('created_desc') + expect(sort_options[2]['text']).to eq(s_('SortOptions|Last created')) + + expect(sort_options[3]['value']).to eq('created_asc') + expect(sort_options[3]['text']).to eq(s_('SortOptions|Oldest created')) + + expect(sort_options[4]['value']).to eq('latest_activity_desc') + expect(sort_options[4]['text']).to eq(_('Updated date')) + + expect(sort_options[5]['value']).to eq('latest_activity_asc') + expect(sort_options[5]['text']).to eq(s_('SortOptions|Oldest updated')) + + expect(sort_options[6]['value']).to eq('storage_size_desc') + expect(sort_options[6]['text']).to eq(s_('SortOptions|Largest group')) + end + + context 'when a sort param is present' do + it 'returns a sorted by name_asc result' do + get :index, params: { sort: 'name_asc' } + + expect(assigns(:groups)).to eq([group, group_3, group_2]) + end + end + + context 'when a name param is present' do + it 'returns a search by name result' do + get :index, params: { name: 'Ygr' } + + expect(assigns(:groups)).to eq([group_2]) + end + + it 'returns an empty list if no match' do + get :index, params: { name: 'nomatch' } + + expect(assigns(:groups)).to be_empty + end + end + + context 'when page is specified' do + before do + allow(Kaminari.config).to receive(:default_per_page).and_return(1) + end + + it 'redirects to the page' do + get :index, params: { page: 1 } + + expect(response).to have_gitlab_http_status(:ok) + expect(assigns(:groups).current_page).to eq(1) + expect(assigns(:groups)).to eq([group]) + end + + it 'redirects to the page' do + get :index, params: { page: 2 } + + expect(response).to have_gitlab_http_status(:ok) + expect(assigns(:groups).current_page).to eq(2) + expect(assigns(:groups)).to eq([group_2]) + end + end + end + describe 'DELETE #destroy' do it 'schedules a group destroy' do Sidekiq::Testing.fake! do diff --git a/spec/controllers/admin/runners_controller_spec.rb b/spec/controllers/admin/runners_controller_spec.rb index 6fa8d2c61c1..5f98004e9cf 100644 --- a/spec/controllers/admin/runners_controller_spec.rb +++ b/spec/controllers/admin/runners_controller_spec.rb @@ -106,13 +106,11 @@ RSpec.describe Admin::RunnersController, feature_category: :runner_fleet do subject(:request) { post :update, params: runner_params } context 'with update succeeding' do - before do + it 'updates the runner and ticks the queue' do expect_next_instance_of(Ci::Runners::UpdateRunnerService, runner) do |service| expect(service).to receive(:execute).with(anything).and_call_original end - end - it 'updates the runner and ticks the queue' do expect { request }.to change { runner.ensure_runner_queue_value } runner.reload @@ -123,13 +121,11 @@ RSpec.describe Admin::RunnersController, feature_category: :runner_fleet do end context 'with update failing' do - before do + it 'does not update runner or tick the queue' do expect_next_instance_of(Ci::Runners::UpdateRunnerService, runner) do |service| expect(service).to receive(:execute).with(anything).and_return(ServiceResponse.error(message: 'failure')) end - end - it 'does not update runner or tick the queue' do expect { request }.not_to change { runner.ensure_runner_queue_value } expect { request }.not_to change { runner.reload.description } diff --git a/spec/controllers/concerns/continue_params_spec.rb b/spec/controllers/concerns/continue_params_spec.rb index 9ac7087430e..a9899447054 100644 --- a/spec/controllers/concerns/continue_params_spec.rb +++ b/spec/controllers/concerns/continue_params_spec.rb @@ -34,7 +34,7 @@ RSpec.describe ContinueParams do strong_continue_params(to: '/hello', notice: 'world', notice_now: '!', something: 'else') end - expect(controller.continue_params.keys).to contain_exactly(*%w(to notice notice_now)) + expect(controller.continue_params.keys).to contain_exactly(*%w[to notice notice_now]) end it 'does not allow cross host redirection' do diff --git a/spec/controllers/concerns/onboarding/status_spec.rb b/spec/controllers/concerns/onboarding/status_spec.rb index fe7c5ac6346..6fcbd059947 100644 --- a/spec/controllers/concerns/onboarding/status_spec.rb +++ b/spec/controllers/concerns/onboarding/status_spec.rb @@ -5,15 +5,8 @@ require 'spec_helper' RSpec.describe Onboarding::Status, feature_category: :onboarding do let_it_be(:member) { create(:group_member) } let_it_be(:user) { member.user } - let_it_be(:tasks_to_be_done) { %w[ci code] } let_it_be(:source) { member.group } - describe '#continue_full_onboarding?' do - subject { described_class.new(nil, {}, user).continue_full_onboarding? } - - it { is_expected.to eq(false) } - end - describe '#single_invite?' do subject { described_class.new(nil, nil, user).single_invite? } diff --git a/spec/controllers/concerns/product_analytics_tracking_spec.rb b/spec/controllers/concerns/product_analytics_tracking_spec.rb index 1394325014b..5c69af48e65 100644 --- a/spec/controllers/concerns/product_analytics_tracking_spec.rb +++ b/spec/controllers/concerns/product_analytics_tracking_spec.rb @@ -10,15 +10,17 @@ RSpec.describe ProductAnalyticsTracking, :snowplow, feature_category: :product_a let(:event_name) { 'an_event' } let(:event_action) { 'an_action' } let(:event_label) { 'a_label' } - let!(:group) { create(:group) } + let_it_be(:project) { create(:project) } + subject(:track_internal_event) { get :show, params: { id: 1 } } + describe '.track_internal_event' do controller(ApplicationController) do include ProductAnalyticsTracking - skip_before_action :authenticate_user!, only: [:show] + skip_before_action :authenticate_user!, only: [:index] track_internal_event :index, :show, name: 'g_compliance_dashboard', conditions: [:custom_condition?] def index @@ -58,8 +60,6 @@ RSpec.describe ProductAnalyticsTracking, :snowplow, feature_category: :product_a context 'when user is logged in' do let(:namespace) { project.namespace } - subject(:track_internal_event) { get :index } - before do sign_in(user) end @@ -83,7 +83,7 @@ RSpec.describe ProductAnalyticsTracking, :snowplow, feature_category: :product_a it 'does not track the event if the format is not HTML' do expect_no_internal_tracking - get :index, format: :json + get :show, params: { id: 1, format: :json } end it 'does not track the event if a custom condition returns false' do @@ -96,34 +96,10 @@ RSpec.describe ProductAnalyticsTracking, :snowplow, feature_category: :product_a end context 'when user is not logged in' do - let(:visitor_id) { SecureRandom.uuid } - - it 'tracks the event when there is a visitor id' do - cookies[:visitor_id] = { value: visitor_id, expires: 24.months } - - expect_internal_tracking(tracked_user: nil) - - get :show, params: { id: 1 } - end - - context 'and there is no visitor_id' do - it 'does not track the event' do - expect_no_internal_tracking - - subject - end - end - end - - context 'when there is no custom_id set' do - before do - allow(controller).to receive(:get_custom_id).and_return(nil) - end - - it 'does not track' do + it 'does not track the event' do expect_no_internal_tracking - subject + get :index end end end diff --git a/spec/controllers/concerns/send_file_upload_spec.rb b/spec/controllers/concerns/send_file_upload_spec.rb index bf6b68df54e..d58f07a92a6 100644 --- a/spec/controllers/concerns/send_file_upload_spec.rb +++ b/spec/controllers/concerns/send_file_upload_spec.rb @@ -193,7 +193,7 @@ RSpec.describe SendFileUpload, feature_category: :user_profile do it 'sends a file with a custom type' do headers = double - expected_headers = /response-content-disposition=attachment%3B%20filename%3D%22test.js%22%3B%20filename%2A%3DUTF-8%27%27test.js&response-content-type=application%2Fjavascript/ + expected_headers = /response-content-disposition=attachment%3B%20filename%3D%22test.js%22%3B%20filename%2A%3DUTF-8%27%27test.js&response-content-type=text%2Fjavascript/ expect(Gitlab::Workhorse).to receive(:send_url).with(expected_headers).and_call_original expect(headers).to receive(:store).with(Gitlab::Workhorse::SEND_DATA_HEADER, /^send-url:/) diff --git a/spec/controllers/graphql_controller_spec.rb b/spec/controllers/graphql_controller_spec.rb index 8fcbf4049a5..bc73168ff1a 100644 --- a/spec/controllers/graphql_controller_spec.rb +++ b/spec/controllers/graphql_controller_spec.rb @@ -317,6 +317,73 @@ RSpec.describe GraphqlController, feature_category: :integrations do subject { post :execute, params: { query: query, access_token: token.token } } + shared_examples 'invalid token' do + it 'returns 401 with invalid token message' do + subject + + expect(response).to have_gitlab_http_status(:unauthorized) + expect_graphql_errors_to_include('Invalid token') + end + end + + context 'with an invalid token' do + context 'with auth header' do + subject do + request.headers[header] = 'invalid' + post :execute, params: { query: query, user: nil } + end + + context 'with private-token' do + let(:header) { 'Private-Token' } + + it_behaves_like 'invalid token' + end + + context 'with job-token' do + let(:header) { 'Job-Token' } + + it_behaves_like 'invalid token' + end + + context 'with deploy-token' do + let(:header) { 'Deploy-Token' } + + it_behaves_like 'invalid token' + end + end + + context 'with authorization bearer (oauth token)' do + subject do + request.headers['Authorization'] = 'Bearer invalid' + post :execute, params: { query: query, user: nil } + end + + it_behaves_like 'invalid token' + end + + context 'with auth param' do + subject { post :execute, params: { query: query, user: nil }.merge(header) } + + context 'with private_token' do + let(:header) { { private_token: 'invalid' } } + + it_behaves_like 'invalid token' + end + + context 'with job_token' do + let(:header) { { job_token: 'invalid' } } + + it_behaves_like 'invalid token' + end + + context 'with token' do + let(:header) { { token: 'invalid' } } + + it_behaves_like 'invalid token' + end + end + end + context 'when the user is a project bot' do let(:user) { create(:user, :project_bot, last_activity_on: last_activity_on) } @@ -471,62 +538,81 @@ RSpec.describe GraphqlController, feature_category: :integrations do context 'when querying an IntrospectionQuery', :use_clean_rails_memory_store_caching do let_it_be(:query) { File.read(Rails.root.join('spec/fixtures/api/graphql/introspection.graphql')) } - it 'caches IntrospectionQuery even when operationName is not given' do - expect(GitlabSchema).to receive(:execute).exactly(:once) - - post :execute, params: { query: query } - post :execute, params: { query: query } - end + context 'in dev or test env' do + before do + allow(Gitlab).to receive(:dev_or_test_env?).and_return(true) + end - it 'caches the IntrospectionQuery' do - expect(GitlabSchema).to receive(:execute).exactly(:once) + it 'does not cache IntrospectionQuery' do + expect(GitlabSchema).to receive(:execute).exactly(:twice) - post :execute, params: { query: query, operationName: 'IntrospectionQuery' } - post :execute, params: { query: query, operationName: 'IntrospectionQuery' } + post :execute, params: { query: query } + post :execute, params: { query: query } + end end - it 'caches separately for both remove_deprecated set to true and false' do - expect(GitlabSchema).to receive(:execute).exactly(:twice) + context 'in env different from dev or test' do + before do + allow(Gitlab).to receive(:dev_or_test_env?).and_return(false) + end - post :execute, params: { query: query, operationName: 'IntrospectionQuery', remove_deprecated: true } - post :execute, params: { query: query, operationName: 'IntrospectionQuery', remove_deprecated: true } + it 'caches IntrospectionQuery even when operationName is not given' do + expect(GitlabSchema).to receive(:execute).exactly(:once) - # We clear this instance variable to reset remove_deprecated - subject.remove_instance_variable(:@context) if subject.instance_variable_defined?(:@context) + post :execute, params: { query: query } + post :execute, params: { query: query } + end - post :execute, params: { query: query, operationName: 'IntrospectionQuery', remove_deprecated: false } - post :execute, params: { query: query, operationName: 'IntrospectionQuery', remove_deprecated: false } - end + it 'caches the IntrospectionQuery' do + expect(GitlabSchema).to receive(:execute).exactly(:once) - it 'has a different cache for each Gitlab.revision' do - expect(GitlabSchema).to receive(:execute).exactly(:twice) + post :execute, params: { query: query, operationName: 'IntrospectionQuery' } + post :execute, params: { query: query, operationName: 'IntrospectionQuery' } + end - post :execute, params: { query: query, operationName: 'IntrospectionQuery' } + it 'caches separately for both remove_deprecated set to true and false' do + expect(GitlabSchema).to receive(:execute).exactly(:twice) - allow(Gitlab).to receive(:revision).and_return('new random value') + post :execute, params: { query: query, operationName: 'IntrospectionQuery', remove_deprecated: true } + post :execute, params: { query: query, operationName: 'IntrospectionQuery', remove_deprecated: true } - post :execute, params: { query: query, operationName: 'IntrospectionQuery' } - end + # We clear this instance variable to reset remove_deprecated + subject.remove_instance_variable(:@context) if subject.instance_variable_defined?(:@context) - context 'when there is an unknown introspection query' do - let(:query) { File.read(Rails.root.join('spec/fixtures/api/graphql/fake_introspection.graphql')) } + post :execute, params: { query: query, operationName: 'IntrospectionQuery', remove_deprecated: false } + post :execute, params: { query: query, operationName: 'IntrospectionQuery', remove_deprecated: false } + end - it 'does not cache an unknown introspection query' do + it 'has a different cache for each Gitlab.revision' do expect(GitlabSchema).to receive(:execute).exactly(:twice) post :execute, params: { query: query, operationName: 'IntrospectionQuery' } + + allow(Gitlab).to receive(:revision).and_return('new random value') + post :execute, params: { query: query, operationName: 'IntrospectionQuery' } end - end - it 'hits the cache even if the whitespace in the query differs' do - query_1 = File.read(Rails.root.join('spec/fixtures/api/graphql/introspection.graphql')) - query_2 = "#{query_1} " # add a couple of spaces to change the fingerprint + context 'when there is an unknown introspection query' do + let(:query) { File.read(Rails.root.join('spec/fixtures/api/graphql/fake_introspection.graphql')) } + + it 'does not cache an unknown introspection query' do + expect(GitlabSchema).to receive(:execute).exactly(:twice) + + post :execute, params: { query: query, operationName: 'IntrospectionQuery' } + post :execute, params: { query: query, operationName: 'IntrospectionQuery' } + end + end + + it 'hits the cache even if the whitespace in the query differs' do + query_1 = File.read(Rails.root.join('spec/fixtures/api/graphql/introspection.graphql')) + query_2 = "#{query_1} " # add a couple of spaces to change the fingerprint - expect(GitlabSchema).to receive(:execute).exactly(:once) + expect(GitlabSchema).to receive(:execute).exactly(:once) - post :execute, params: { query: query_1, operationName: 'IntrospectionQuery' } - post :execute, params: { query: query_2, operationName: 'IntrospectionQuery' } + post :execute, params: { query: query_1, operationName: 'IntrospectionQuery' } + post :execute, params: { query: query_2, operationName: 'IntrospectionQuery' } + end end it 'fails if the GraphiQL gem version is not 1.8.0' do @@ -542,7 +628,7 @@ RSpec.describe GraphqlController, feature_category: :integrations do let_it_be(:admin) { create(:admin) } let_it_be(:project) { create(:project) } - let(:graphql_query) { graphql_query_for('project', { 'fullPath' => project.full_path }, %w(id name)) } + let(:graphql_query) { graphql_query_for('project', { 'fullPath' => project.full_path }, %w[id name]) } before do sign_in(admin) @@ -588,8 +674,8 @@ RSpec.describe GraphqlController, feature_category: :integrations do end describe '#append_info_to_payload' do - let(:query_1) { { query: graphql_query_for('project', { 'fullPath' => 'foo' }, %w(id name), 'getProject_1') } } - let(:query_2) { { query: graphql_query_for('project', { 'fullPath' => 'bar' }, %w(id), 'getProject_2') } } + let(:query_1) { { query: graphql_query_for('project', { 'fullPath' => 'foo' }, %w[id name], 'getProject_1') } } + let(:query_2) { { query: graphql_query_for('project', { 'fullPath' => 'bar' }, %w[id], 'getProject_2') } } let(:graphql_queries) { [query_1, query_2] } let(:log_payload) { {} } let(:expected_logs) do diff --git a/spec/controllers/groups/releases_controller_spec.rb b/spec/controllers/groups/releases_controller_spec.rb index 40e8cb4efc5..4b4333dea0e 100644 --- a/spec/controllers/groups/releases_controller_spec.rb +++ b/spec/controllers/groups/releases_controller_spec.rb @@ -56,7 +56,7 @@ RSpec.describe Groups::ReleasesController do index - expect(json_response.map { |r| r['tag'] }).to match_array(%w(p2 p1 v2 v1)) + expect(json_response.map { |r| r['tag'] }).to match_array(%w[p2 p1 v2 v1]) end end diff --git a/spec/controllers/groups/runners_controller_spec.rb b/spec/controllers/groups/runners_controller_spec.rb index a4e55a89f41..d48e9ff0d51 100644 --- a/spec/controllers/groups/runners_controller_spec.rb +++ b/spec/controllers/groups/runners_controller_spec.rb @@ -49,7 +49,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do end context 'when the user is a maintainer' do - before do + before_all do group.add_maintainer(user) end @@ -64,7 +64,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do end context 'when the user is an owner' do - before do + before_all do group.add_owner(user) end @@ -79,7 +79,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do end context 'when user is not maintainer' do - before do + before_all do group.add_developer(user) end @@ -89,7 +89,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do describe '#new' do context 'when user is owner' do - before do + before_all do group.add_owner(user) end @@ -102,7 +102,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do end context 'when user is not owner' do - before do + before_all do group.add_maintainer(user) end @@ -118,7 +118,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do subject(:register) { get :register, params: { group_id: group, id: new_runner } } context 'when user is owner' do - before do + before_all do group.add_owner(user) end @@ -145,7 +145,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do end context 'when user is not owner' do - before do + before_all do group.add_maintainer(user) end @@ -163,7 +163,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do describe '#show' do context 'when user is maintainer' do - before do + before_all do group.add_maintainer(user) end @@ -190,7 +190,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do end context 'when user is not maintainer' do - before do + before_all do group.add_developer(user) end @@ -216,7 +216,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do describe '#edit' do context 'when user is owner' do - before do + before_all do group.add_owner(user) end @@ -248,7 +248,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do end context 'when user is maintainer' do - before do + before_all do group.add_maintainer(user) end @@ -273,7 +273,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do end context 'when user is not maintainer' do - before do + before_all do group.add_developer(user) end @@ -329,7 +329,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do end context 'when user is owner' do - before do + before_all do group.add_owner(user) end @@ -353,7 +353,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do end context 'when user is maintainer' do - before do + before_all do group.add_maintainer(user) end @@ -377,7 +377,7 @@ RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do end context 'when user is not maintainer' do - before do + before_all do group.add_developer(user) end diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 87a30ed1234..31257fd3a30 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -673,14 +673,6 @@ RSpec.describe GroupsController, factory_default: :keep, feature_category: :code expect(controller).to set_flash[:notice] end - it 'does not update the path on error' do - allow_any_instance_of(Group).to receive(:move_dir).and_raise(Gitlab::UpdatePathError) - post :update, params: { id: group.to_param, group: { path: 'new_path' } } - - expect(assigns(:group).errors).not_to be_empty - expect(assigns(:group).path).not_to eq('new_path') - end - it 'updates the project_creation_level successfully' do post :update, params: { id: group.to_param, group: { project_creation_level: ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS } } diff --git a/spec/controllers/import/bitbucket_server_controller_spec.rb b/spec/controllers/import/bitbucket_server_controller_spec.rb index b2a56423253..3266c4d4d39 100644 --- a/spec/controllers/import/bitbucket_server_controller_spec.rb +++ b/spec/controllers/import/bitbucket_server_controller_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Import::BitbucketServerController, feature_category: :importers d let(:repo_slug) { 'some-repo' } let(:repo_id) { "#{project_key}/#{repo_slug}" } let(:client) { instance_double(BitbucketServer::Client) } + let(:timeout_strategy) { "pessimistic" } def assign_session_tokens session[:bitbucket_server_url] = 'http://localhost:7990' @@ -44,7 +45,7 @@ RSpec.describe Import::BitbucketServerController, feature_category: :importers d it 'returns the new project' do allow(Gitlab::BitbucketServerImport::ProjectCreator) - .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything) + .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything, timeout_strategy) .and_return(double(execute: project)) post :create, params: { repo_id: repo_id }, format: :json @@ -57,7 +58,7 @@ RSpec.describe Import::BitbucketServerController, feature_category: :importers d it 'successfully creates a project' do allow(Gitlab::BitbucketServerImport::ProjectCreator) - .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything) + .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything, timeout_strategy) .and_return(double(execute: project)) post :create, params: { repo_id: repo_id }, format: :json @@ -88,7 +89,7 @@ RSpec.describe Import::BitbucketServerController, feature_category: :importers d it 'returns an error when the project cannot be saved' do allow(Gitlab::BitbucketServerImport::ProjectCreator) - .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything) + .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything, timeout_strategy) .and_return(double(execute: build(:project))) post :create, params: { repo_id: repo_id }, format: :json diff --git a/spec/controllers/import/github_controller_spec.rb b/spec/controllers/import/github_controller_spec.rb index bf56043a496..aafba6e2b9f 100644 --- a/spec/controllers/import/github_controller_spec.rb +++ b/spec/controllers/import/github_controller_spec.rb @@ -66,31 +66,11 @@ RSpec.describe Import::GithubController, feature_category: :importers do context "when auth state param is present in session" do let(:valid_auth_state) { "secret-state" } - context 'when remove_legacy_github_client feature is disabled' do - before do - stub_feature_flags(remove_legacy_github_client: false) - allow_next_instance_of(Gitlab::LegacyGithubImport::Client) do |client| - allow(client).to receive(:get_token).and_return(token) - end - session[:github_auth_state_key] = valid_auth_state - end - - it "updates access token if state param is valid" do - token = "asdasd12345" - - get :callback, params: { state: valid_auth_state } - - expect(session[:github_access_token]).to eq(token) - expect(controller).to redirect_to(status_import_github_url) - end - - it "includes namespace_id from query params if it is present" do - namespace_id = 1 - - get :callback, params: { state: valid_auth_state, namespace_id: namespace_id } - - expect(controller).to redirect_to(status_import_github_url(namespace_id: namespace_id)) + before do + allow_next_instance_of(OAuth2::Client) do |client| + allow(client).to receive_message_chain(:auth_code, :get_token, :token).and_return(token) end + session[:github_auth_state_key] = valid_auth_state end it "reports an error if state param is invalid" do @@ -100,31 +80,21 @@ RSpec.describe Import::GithubController, feature_category: :importers do expect(flash[:alert]).to eq('Access denied to your GitHub account.') end - context 'when remove_legacy_github_client feature is enabled' do - before do - stub_feature_flags(remove_legacy_github_client: true) - allow_next_instance_of(OAuth2::Client) do |client| - allow(client).to receive_message_chain(:auth_code, :get_token, :token).and_return(token) - end - session[:github_auth_state_key] = valid_auth_state - end + it "updates access token if state param is valid" do + token = "asdasd12345" - it "updates access token if state param is valid" do - token = "asdasd12345" + get :callback, params: { state: valid_auth_state } - get :callback, params: { state: valid_auth_state } - - expect(session[:github_access_token]).to eq(token) - expect(controller).to redirect_to(status_import_github_url) - end + expect(session[:github_access_token]).to eq(token) + expect(controller).to redirect_to(status_import_github_url) + end - it "includes namespace_id from query params if it is present" do - namespace_id = 1 + it "includes namespace_id from query params if it is present" do + namespace_id = 1 - get :callback, params: { state: valid_auth_state, namespace_id: namespace_id } + get :callback, params: { state: valid_auth_state, namespace_id: namespace_id } - expect(controller).to redirect_to(status_import_github_url(namespace_id: namespace_id)) - end + expect(controller).to redirect_to(status_import_github_url(namespace_id: namespace_id)) end end end @@ -138,7 +108,6 @@ RSpec.describe Import::GithubController, feature_category: :importers do it 'calls repos list from provider with expected args' do expect_next_instance_of(Gitlab::GithubImport::Clients::Proxy) do |client| expect(client).to receive(:repos) - .with(expected_filter, expected_options) .and_return({ repos: [], page_info: {}, count: 0 }) end @@ -160,10 +129,6 @@ RSpec.describe Import::GithubController, feature_category: :importers do let(:pagination_params) { { before: nil, after: nil } } let(:relation_params) { { relation_type: nil, organization_login: '' } } let(:provider_repos) { [] } - let(:expected_filter) { '' } - let(:expected_options) do - pagination_params.merge(relation_params).merge(first: 25) - end before do allow_next_instance_of(Gitlab::GithubImport::Clients::Proxy) do |proxy| @@ -287,21 +252,11 @@ RSpec.describe Import::GithubController, feature_category: :importers do let(:organization_login) { 'test-login' } let(:params) { pagination_params.merge(relation_type: 'organization', organization_login: organization_login) } let(:pagination_defaults) { { first: 25 } } - let(:expected_options) do - pagination_defaults.merge(pagination_params).merge( - relation_type: 'organization', organization_login: organization_login - ) - end it_behaves_like 'calls repos through Clients::Proxy with expected args' context 'when organization_login is too long and with ":"' do let(:organization_login) { ":#{Array.new(270) { ('a'..'z').to_a.sample }.join}" } - let(:expected_options) do - pagination_defaults.merge(pagination_params).merge( - relation_type: 'organization', organization_login: organization_login.slice(1, 254) - ) - end it_behaves_like 'calls repos through Clients::Proxy with expected args' end @@ -310,7 +265,6 @@ RSpec.describe Import::GithubController, feature_category: :importers do context 'when filtering' do let(:filter_param) { FFaker::Lorem.word } let(:params) { { filter: filter_param } } - let(:expected_filter) { filter_param } it_behaves_like 'calls repos through Clients::Proxy with expected args' @@ -332,7 +286,6 @@ RSpec.describe Import::GithubController, feature_category: :importers do context 'when user input contains colons and spaces' do let(:filter_param) { ' test1:test2 test3 : test4 ' } - let(:expected_filter) { 'test1test2test3test4' } it_behaves_like 'calls repos through Clients::Proxy with expected args' end diff --git a/spec/controllers/jira_connect/app_descriptor_controller_spec.rb b/spec/controllers/jira_connect/app_descriptor_controller_spec.rb index 48b315646de..ea6cb688409 100644 --- a/spec/controllers/jira_connect/app_descriptor_controller_spec.rb +++ b/spec/controllers/jira_connect/app_descriptor_controller_spec.rb @@ -42,7 +42,7 @@ RSpec.describe JiraConnect::AppDescriptorController, feature_category: :integrat authentication: { type: 'jwt' }, - scopes: %w(READ WRITE DELETE), + scopes: %w[READ WRITE DELETE], apiVersion: 1, apiMigrations: { 'context-qsh': true, @@ -71,7 +71,7 @@ RSpec.describe JiraConnect::AppDescriptorController, feature_category: :integrat name: { value: 'GitLab' }, url: 'https://gitlab.com', logoUrl: logo_url, - capabilities: %w(branch commit pull_request) + capabilities: %w[branch commit pull_request] }, jiraBuildInfoProvider: common_module_properties.merge( actions: {}, diff --git a/spec/controllers/oauth/applications_controller_spec.rb b/spec/controllers/oauth/applications_controller_spec.rb index 44deeb6c47e..dcd817861a7 100644 --- a/spec/controllers/oauth/applications_controller_spec.rb +++ b/spec/controllers/oauth/applications_controller_spec.rb @@ -198,7 +198,7 @@ RSpec.describe Oauth::ApplicationsController, feature_category: :system_access d end context 'when scopes are invalid' do - let(:scopes) { %w(api foo) } + let(:scopes) { %w[api foo] } render_views diff --git a/spec/controllers/oauth/tokens_controller_spec.rb b/spec/controllers/oauth/tokens_controller_spec.rb index 389153d138e..489470dc0df 100644 --- a/spec/controllers/oauth/tokens_controller_spec.rb +++ b/spec/controllers/oauth/tokens_controller_spec.rb @@ -2,8 +2,64 @@ require 'spec_helper' -RSpec.describe Oauth::TokensController do +RSpec.describe Oauth::TokensController, feature_category: :user_management do + let(:user) { create(:user) } + it 'includes Two-factor enforcement concern' do expect(described_class.included_modules.include?(EnforcesTwoFactorAuthentication)).to eq(true) end + + describe '#append_info_to_payload' do + controller(described_class) do + attr_reader :last_payload + + def create + render html: 'authenticated' + end + + def append_info_to_payload(payload) + super + + @last_payload = payload + end + end + + it 'does log correlation id' do + Labkit::Correlation::CorrelationId.use_id('new-id') do + post :create + end + + expect(controller.last_payload).to include('correlation_id' => 'new-id') + end + + it 'adds context metadata to the payload' do + sign_in user + + post :create + + expect(controller.last_payload[:metadata]).to include(Gitlab::ApplicationContext.current) + end + + it 'logs response length' do + sign_in user + + post :create + + expect(controller.last_payload[:response_bytes]).to eq('authenticated'.bytesize) + end + + context 'with log_response_length disabled' do + before do + stub_feature_flags(log_response_length: false) + end + + it 'logs response length' do + sign_in user + + post :create + + expect(controller.last_payload).not_to include(:response_bytes) + end + end + end end diff --git a/spec/controllers/omniauth_callbacks_controller_spec.rb b/spec/controllers/omniauth_callbacks_controller_spec.rb index 8d2face0233..847f7aeae7c 100644 --- a/spec/controllers/omniauth_callbacks_controller_spec.rb +++ b/spec/controllers/omniauth_callbacks_controller_spec.rb @@ -44,7 +44,7 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: Rails.application.env_config['omniauth.auth'] = @original_env_config_omniauth_auth end - context 'authentication succeeds' do + context 'when authentication succeeds' do let(:extern_uid) { 'my-uid' } let(:provider) { :github } @@ -77,7 +77,7 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: end end - context 'a deactivated user' do + context 'for a deactivated user' do let(:provider) { :github } let(:extern_uid) { 'my-uid' } @@ -216,8 +216,8 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: end end - context 'strategies' do - shared_context 'sign_up' do + context 'with strategies' do + shared_context 'with sign_up' do let(:user) { double(email: 'new@example.com') } before do @@ -225,7 +225,7 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: end end - context 'github' do + context 'for github' do let(:extern_uid) { 'my-uid' } let(:provider) { :github } @@ -299,7 +299,7 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: end context 'for sign up' do - include_context 'sign_up' + include_context 'with sign_up' it 'is allowed' do post provider @@ -307,10 +307,10 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: expect(request.env['warden']).to be_authenticated end - it 'redirects to welcome path' do - post provider + it_behaves_like Onboarding::Redirectable do + let(:email) { user.email } - expect(response).to redirect_to(users_sign_up_welcome_path) + subject(:post_create) { post provider } end end @@ -341,8 +341,8 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: expect { post provider }.to change { user.reload.identities.count }.by(1) end - context 'sign up' do - include_context 'sign_up' + context 'for sign up' do + include_context 'with sign_up' it 'is prevented' do post provider @@ -353,7 +353,7 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: end end - context 'auth0' do + context 'for auth0' do let(:extern_uid) { '' } let(:provider) { :auth0 } @@ -366,7 +366,7 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: end end - context 'atlassian_oauth2' do + context 'for atlassian_oauth2' do let(:provider) { :atlassian_oauth2 } let(:extern_uid) { 'my-uid' } @@ -424,7 +424,7 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: end end - context 'salesforce' do + context 'for salesforce' do let(:extern_uid) { 'my-uid' } let(:provider) { :salesforce } let(:additional_info) { { extra: { email_verified: false } } } @@ -440,7 +440,7 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: end context 'with verified email' do - include_context 'sign_up' + include_context 'with sign_up' let(:additional_info) { { extra: { email_verified: true } } } it 'allows sign in' do @@ -532,7 +532,7 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: let(:post_action) { post :saml, params: { SAMLResponse: mock_saml_response } } end - context 'sign up' do + context 'for sign up' do before do user.destroy! end @@ -683,7 +683,7 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: expect(subject.current_user_mode.admin_mode?).to be(expected_admin_mode) end - context 'user and admin mode requested by the same user' do + context 'when user and admin mode is requested by the same user' do before do sign_in user @@ -724,7 +724,7 @@ RSpec.describe OmniauthCallbacksController, type: :controller, feature_category: end end - context 'user and admin mode requested by different users' do + context 'when user and admin mode is requested by different users' do let(:reauth_extern_uid) { 'another_uid' } let(:reauth_user) { create(:omniauth_user, extern_uid: reauth_extern_uid, provider: provider) } diff --git a/spec/controllers/profiles/personal_access_tokens_controller_spec.rb b/spec/controllers/profiles/personal_access_tokens_controller_spec.rb index 14f3f5c23cd..9c9a9a28879 100644 --- a/spec/controllers/profiles/personal_access_tokens_controller_spec.rb +++ b/spec/controllers/profiles/personal_access_tokens_controller_spec.rb @@ -109,53 +109,5 @@ RSpec.describe Profiles::PersonalAccessTokensController do it 'sets available scopes' do expect(assigns(:scopes)).to eq(Gitlab::Auth.available_scopes_for(access_token_user)) end - - context 'with feature flag k8s_proxy_pat disabled' do - before do - stub_feature_flags(k8s_proxy_pat: false) - # Impersonation and inactive personal tokens are ignored - create(:personal_access_token, :impersonation, user: access_token_user) - create(:personal_access_token, :revoked, user: access_token_user) - get :index - end - - it "only includes details of active personal access tokens" do - active_personal_access_tokens_detail = - ::PersonalAccessTokenSerializer.new.represent([active_personal_access_token]) - - expect(assigns(:active_access_tokens).to_json).to eq(active_personal_access_tokens_detail.to_json) - end - - it "builds a PAT with name and scopes from params" do - name = 'My PAT' - scopes = 'api,read_user' - - get :index, params: { name: name, scopes: scopes } - - expect(assigns(:personal_access_token)).to have_attributes( - name: eq(name), - scopes: contain_exactly(:api, :read_user) - ) - end - - it 'returns 404 when personal access tokens are disabled' do - allow(::Gitlab::CurrentSettings).to receive_messages(personal_access_tokens_disabled?: true) - - get :index - - expect(response).to have_gitlab_http_status(:not_found) - end - - it 'returns tokens for json format' do - get :index, params: { format: :json } - - expect(json_response.count).to eq(1) - end - - it 'sets available scopes' do - expect(assigns(:scopes)) - .to eq(Gitlab::Auth.available_scopes_for(access_token_user) - [Gitlab::Auth::K8S_PROXY_SCOPE]) - end - end end end diff --git a/spec/controllers/profiles/two_factor_auths_controller_spec.rb b/spec/controllers/profiles/two_factor_auths_controller_spec.rb index dde0af3c543..0c4280467f4 100644 --- a/spec/controllers/profiles/two_factor_auths_controller_spec.rb +++ b/spec/controllers/profiles/two_factor_auths_controller_spec.rb @@ -165,11 +165,11 @@ RSpec.describe Profiles::TwoFactorAuthsController, feature_category: :system_acc end it 'presents plaintext codes for the user to save' do - expect(user).to receive(:generate_otp_backup_codes!).and_return(%w(a b c)) + expect(user).to receive(:generate_otp_backup_codes!).and_return(%w[a b c]) go - expect(assigns[:codes]).to match_array %w(a b c) + expect(assigns[:codes]).to match_array %w[a b c] end it 'calls to delete other sessions' do @@ -216,11 +216,11 @@ RSpec.describe Profiles::TwoFactorAuthsController, feature_category: :system_acc end it 'presents plaintext codes for the user to save' do - expect(user).to receive(:generate_otp_backup_codes!).and_return(%w(a b c)) + expect(user).to receive(:generate_otp_backup_codes!).and_return(%w[a b c]) go - expect(assigns[:codes]).to match_array %w(a b c) + expect(assigns[:codes]).to match_array %w[a b c] end it 'calls to delete other sessions' do @@ -288,10 +288,10 @@ RSpec.describe Profiles::TwoFactorAuthsController, feature_category: :system_acc let(:current_password) { user.password } it 'presents plaintext codes for the user to save' do - expect(user).to receive(:generate_otp_backup_codes!).and_return(%w(a b c)) + expect(user).to receive(:generate_otp_backup_codes!).and_return(%w[a b c]) post :codes, params: { current_password: current_password } - expect(assigns[:codes]).to match_array %w(a b c) + expect(assigns[:codes]).to match_array %w[a b c] end it 'persists the generated codes' do diff --git a/spec/controllers/projects/artifacts_controller_spec.rb b/spec/controllers/projects/artifacts_controller_spec.rb index 44615506e5d..31e6d6ae5e6 100644 --- a/spec/controllers/projects/artifacts_controller_spec.rb +++ b/spec/controllers/projects/artifacts_controller_spec.rb @@ -409,7 +409,7 @@ RSpec.describe Projects::ArtifactsController, feature_category: :build_artifacts expect(response.headers['Gitlab-Workhorse-Detect-Content-Type']).to eq('true') expect(send_data).to start_with('artifacts-entry:') - expect(params.keys).to eq(%w(Archive Entry)) + expect(params.keys).to eq(%w[Archive Entry]) expect(params['Archive']).to start_with(archive_path) # On object storage, the URL can end with a query string expect(params['Archive']).to match(archive_matcher) diff --git a/spec/controllers/projects/deploy_keys_controller_spec.rb b/spec/controllers/projects/deploy_keys_controller_spec.rb index 52a605cf548..96addb4b6c5 100644 --- a/spec/controllers/projects/deploy_keys_controller_spec.rb +++ b/spec/controllers/projects/deploy_keys_controller_spec.rb @@ -54,7 +54,7 @@ RSpec.describe Projects::DeployKeysController do it 'returns json in a correct format' do get :index, params: params.merge(format: :json) - expect(json_response.keys).to match_array(%w(enabled_keys available_project_keys public_keys)) + expect(json_response.keys).to match_array(%w[enabled_keys available_project_keys public_keys]) expect(json_response['enabled_keys'].count).to eq(1) expect(json_response['available_project_keys'].count).to eq(1) expect(json_response['public_keys'].count).to eq(1) diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index d4f04105605..5024698a769 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -191,7 +191,7 @@ RSpec.describe Projects::IssuesController, :request_store, feature_category: :te it 'redirects to work item page using iid' do make_request - expect(response).to redirect_to(project_work_items_path(project, task.iid, query)) + expect(response).to redirect_to(project_work_item_path(project, task.iid, query)) end end @@ -849,7 +849,7 @@ RSpec.describe Projects::IssuesController, :request_store, feature_category: :te update_issue(issue_params: { assignee_ids: [assignee.id] }) expect(json_response['assignees'].first.keys) - .to include(*%w(id name username avatar_url state web_url)) + .to include(*%w[id name username avatar_url state web_url]) 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 428ce5b5607..1fe297362bf 100644 --- a/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb @@ -97,7 +97,7 @@ RSpec.describe Projects::MergeRequests::ConflictsController, feature_category: : section['lines'].each do |line| if section['conflict'] - expect(line['type']).to be_in(%w(old new)) + expect(line['type']).to be_in(%w[old new]) expect(line.values_at('old_line', 'new_line')).to contain_exactly(nil, a_kind_of(Integer)) elsif line['type'].nil? expect(line['old_line']).not_to eq(nil) diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index a47bb98770c..92bbffdfde5 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -407,7 +407,7 @@ RSpec.describe Projects::MergeRequestsController, feature_category: :code_review update_merge_request({ assignee_ids: [assignee.id] }, format: :json) - expect(json_response['assignees']).to all(include(*%w(name username avatar_url id state web_url))) + expect(json_response['assignees']).to all(include(*%w[name username avatar_url id state web_url])) end end diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index 43e7bafc206..deaed8e1162 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -216,7 +216,7 @@ RSpec.describe Projects::PipelinesController, feature_category: :continuous_inte end def create_all_pipeline_types - %w(pending running success failed canceled).each_with_index do |status, index| + %w[pending running success failed canceled].each_with_index do |status, index| create_pipeline(status, project.commit("HEAD~#{index}")) end @@ -821,7 +821,7 @@ RSpec.describe Projects::PipelinesController, feature_category: :continuous_inte subject { get :charts, params: request_params, format: :html } let(:request_params) { { namespace_id: project.namespace, project_id: project, id: pipeline.id, chart: tab[:chart_param] } } - let(:action) { tab[:event] } + let(:event) { tab[:event] } let(:namespace) { project.namespace } end end diff --git a/spec/controllers/projects/project_members_controller_spec.rb b/spec/controllers/projects/project_members_controller_spec.rb index 9657cf33afd..c20f92cd2f0 100644 --- a/spec/controllers/projects/project_members_controller_spec.rb +++ b/spec/controllers/projects/project_members_controller_spec.rb @@ -98,18 +98,9 @@ RSpec.describe Projects::ProjectMembersController do end end - context 'when invited group members are present' do + shared_examples 'users are invited through groups' do let_it_be(:invited_group_member) { create(:user) } - before do - group.add_owner(invited_group_member) - - project.invited_groups << group - project.add_maintainer(user) - - sign_in(user) - end - context 'when webui_members_inherited_users is disabled' do before do stub_feature_flags(webui_members_inherited_users: false) @@ -128,6 +119,35 @@ RSpec.describe Projects::ProjectMembersController do expect(assigns(:project_members).map(&:user_id)).to include(invited_group_member.id) end end + + context 'when invited group members are present' do + before do + group.add_owner(invited_group_member) + + project.invited_groups << group + project.add_maintainer(user) + + sign_in(user) + end + + include_examples 'users are invited through groups' + end + + context 'when group is invited to project parent' do + let_it_be(:parent_group) { create(:group, :public) } + let_it_be(:project, reload: true) { create(:project, :public, namespace: parent_group) } + + before do + group.add_owner(invited_group_member) + + parent_group.shared_with_groups << group + project.add_maintainer(user) + + sign_in(user) + end + + include_examples 'users are invited through groups' + end end context 'invited members' do diff --git a/spec/controllers/projects/prometheus/metrics_controller_spec.rb b/spec/controllers/projects/prometheus/metrics_controller_spec.rb deleted file mode 100644 index 8f8edebbc30..00000000000 --- a/spec/controllers/projects/prometheus/metrics_controller_spec.rb +++ /dev/null @@ -1,230 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Projects::Prometheus::MetricsController, feature_category: :metrics do - let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project, :with_prometheus_integration) } - - let(:prometheus_adapter) { double('prometheus_adapter', can_query?: true) } - - before do - stub_feature_flags(remove_monitor_metrics: false) - project.add_maintainer(user) - sign_in(user) - end - - describe 'GET #active_common' do - context 'when prometheus_adapter can query' do - before do - allow(controller).to receive(:prometheus_adapter).and_return(prometheus_adapter) - end - - context 'when prometheus metrics are enabled' do - context 'when data is not present' do - before do - allow(prometheus_adapter).to receive(:query).with(:matched_metrics).and_return({}) - end - - it 'returns no content response' do - get :active_common, params: project_params(format: :json) - - expect(response).to have_gitlab_http_status(:no_content) - end - end - - context 'when data is available' do - let(:sample_response) { { some_data: 1 } } - - before do - allow(prometheus_adapter).to receive(:query).with(:matched_metrics).and_return(sample_response) - end - - it 'returns no content response' do - get :active_common, params: project_params(format: :json) - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response).to eq(sample_response.deep_stringify_keys) - end - end - - context 'when requesting non json response' do - it 'returns not found response' do - get :active_common, params: project_params - - expect(response).to have_gitlab_http_status(:not_found) - end - end - end - end - - context 'when prometheus_adapter cannot query' do - it 'renders 404' do - prometheus_adapter = double('prometheus_adapter', can_query?: false) - - allow(controller).to receive(:prometheus_adapter).and_return(prometheus_adapter) - allow(prometheus_adapter).to receive(:query).with(:matched_metrics).and_return({}) - - get :active_common, params: project_params(format: :json) - - expect(response).to have_gitlab_http_status(:not_found) - end - end - - context 'when prometheus_adapter is disabled' do - let(:project) { create(:project) } - - it 'renders 404' do - get :active_common, params: project_params(format: :json) - - expect(response).to have_gitlab_http_status(:not_found) - end - end - - context 'when metrics dashboard feature is unavailable' do - before do - stub_feature_flags(remove_monitor_metrics: true) - end - - it 'renders 404' do - get :active_common, params: project_params(format: :json) - - expect(response).to have_gitlab_http_status(:not_found) - end - end - end - - describe 'POST #validate_query' do - before do - allow(controller).to receive(:prometheus_adapter).and_return(prometheus_adapter) - allow(prometheus_adapter).to receive(:query).with(:validate, query) { validation_result } - end - - let(:query) { 'avg(metric)' } - - context 'validation information is ready' do - let(:validation_result) { { valid: true } } - - it 'validation data is returned' do - post :validate_query, params: project_params(format: :json, query: query) - - expect(json_response).to eq('valid' => true) - end - end - - context 'validation information is not ready' do - let(:validation_result) { nil } - - it 'validation data is returned' do - post :validate_query, params: project_params(format: :json, query: query) - - expect(response).to have_gitlab_http_status(:accepted) - end - end - end - - describe 'GET #index' do - context 'with custom metric present' do - let!(:prometheus_metric) { create(:prometheus_metric, project: project) } - - it 'returns a list of metrics' do - get :index, params: project_params(format: :json) - - expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('prometheus/metrics') - end - end - - context 'without custom metrics ' do - it 'returns an empty json' do - get :index, params: project_params(format: :json) - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response).to eq({}) - end - end - end - - describe 'POST #create' do - context 'metric is valid' do - let(:valid_metric) { { prometheus_metric: { title: 'title', query: 'query', group: 'business', y_label: 'label', unit: 'u', legend: 'legend' } } } - - it 'shows a success flash message' do - post :create, params: project_params(valid_metric) - - expect(flash[:notice]).to include('Metric was successfully added.') - - expect(response).to redirect_to(edit_project_settings_integration_path(project, ::Integrations::Prometheus)) - end - end - - context 'metric is invalid' do - let(:invalid_metric) { { prometheus_metric: { title: 'title' } } } - - it 'renders new metric page' do - post :create, params: project_params(invalid_metric) - - expect(response).to have_gitlab_http_status(:ok) - expect(response).to render_template('new') - end - end - end - - describe 'PUT #update' do - context 'metric is updated' do - let_it_be(:metric) { create(:prometheus_metric, project: project) } - - let(:metric_params) { { prometheus_metric: { title: 'new_title' }, id: metric.id } } - - it 'shows a success flash message' do - put :update, params: project_params(metric_params) - - expect(metric.reload.title).to eq('new_title') - expect(flash[:notice]).to include('Metric was successfully updated.') - expect(response).to redirect_to(edit_project_settings_integration_path(project, ::Integrations::Prometheus)) - end - end - end - - describe 'DELETE #destroy' do - context 'format html' do - let!(:metric) { create(:prometheus_metric, project: project) } - - it 'destroys the metric' do - delete :destroy, params: project_params(id: metric.id) - - expect(response).to redirect_to(edit_project_settings_integration_path(project, ::Integrations::Prometheus)) - expect(PrometheusMetric.find_by(id: metric.id)).to be_nil - end - end - - context 'format json' do - let!(:metric) { create(:prometheus_metric, project: project) } - - it 'destroys the metric' do - delete :destroy, params: project_params(id: metric.id, format: :json) - - expect(response).to have_gitlab_http_status(:ok) - expect(PrometheusMetric.find_by(id: metric.id)).to be_nil - end - end - end - - describe '#prometheus_adapter' do - before do - allow(controller).to receive(:project).and_return(project) - end - - it 'calls prometheus adapter service' do - expect_next_instance_of(::Gitlab::Prometheus::Adapter) do |instance| - expect(instance).to receive(:prometheus_adapter) - end - - subject.__send__(:prometheus_adapter) - end - end - - def project_params(opts = {}) - opts.reverse_merge(namespace_id: project.namespace, project_id: project) - end -end diff --git a/spec/controllers/projects/refs_controller_spec.rb b/spec/controllers/projects/refs_controller_spec.rb index 7ea0e678a41..345e6e2e0de 100644 --- a/spec/controllers/projects/refs_controller_spec.rb +++ b/spec/controllers/projects/refs_controller_spec.rb @@ -26,32 +26,32 @@ RSpec.describe Projects::RefsController, feature_category: :source_code_manageme subject { get :switch, params: params } where(:destination, :ref_type, :path, :redirected_to) do - 'tree' | nil | nil | lazy { project_tree_path(project, id) } - 'tree' | 'heads' | nil | lazy { project_tree_path(project, id) } + 'tree' | nil | nil | lazy { project_tree_path(project, id) } + 'tree' | 'heads' | nil | lazy { project_tree_path(project, id) } 'tree' | nil | 'foo/bar' | lazy { project_tree_path(project, id_and_path) } - 'blob' | nil | nil | lazy { project_blob_path(project, id) } - 'blob' | 'heads' | nil | lazy { project_blob_path(project, id) } + 'blob' | nil | nil | lazy { project_blob_path(project, id) } + 'blob' | 'heads' | nil | lazy { project_blob_path(project, id) } 'blob' | nil | 'foo/bar' | lazy { project_blob_path(project, id_and_path) } - 'graph' | nil | nil | lazy { project_network_path(project, id) } - 'graph' | 'heads' | nil | lazy { project_network_path(project, id, ref_type: 'heads') } + 'graph' | nil | nil | lazy { project_network_path(project, id) } + 'graph' | 'heads' | nil | lazy { project_network_path(project, id, ref_type: 'heads') } 'graph' | nil | 'foo/bar' | lazy { project_network_path(project, id_and_path) } - 'graphs' | nil | nil | lazy { project_graph_path(project, id) } - 'graphs' | 'heads' | nil | lazy { project_graph_path(project, id, ref_type: 'heads') } + 'graphs' | nil | nil | lazy { project_graph_path(project, id) } + 'graphs' | 'heads' | nil | lazy { project_graph_path(project, id, ref_type: 'heads') } 'graphs' | nil | 'foo/bar' | lazy { project_graph_path(project, id_and_path) } - 'find_file' | nil | nil | lazy { project_find_file_path(project, id) } - 'find_file' | 'heads' | nil | lazy { project_find_file_path(project, id) } + 'find_file' | nil | nil | lazy { project_find_file_path(project, id) } + 'find_file' | 'heads' | nil | lazy { project_find_file_path(project, id) } 'find_file' | nil | 'foo/bar' | lazy { project_find_file_path(project, id_and_path) } - 'graphs_commits' | nil | nil | lazy { commits_project_graph_path(project, id) } - 'graphs_commits' | 'heads' | nil | lazy { commits_project_graph_path(project, id) } + 'graphs_commits' | nil | nil | lazy { commits_project_graph_path(project, id) } + 'graphs_commits' | 'heads' | nil | lazy { commits_project_graph_path(project, id) } 'graphs_commits' | nil | 'foo/bar' | lazy { commits_project_graph_path(project, id_and_path) } - 'badges' | nil | nil | lazy { project_settings_ci_cd_path(project, ref: id) } - 'badges' | 'heads' | nil | lazy { project_settings_ci_cd_path(project, ref: id) } + 'badges' | nil | nil | lazy { project_settings_ci_cd_path(project, ref: id) } + 'badges' | 'heads' | nil | lazy { project_settings_ci_cd_path(project, ref: id) } 'badges' | nil | 'foo/bar' | lazy { project_settings_ci_cd_path(project, ref: id_and_path) } - 'commits' | nil | nil | lazy { project_commits_path(project, id) } - 'commits' | 'heads' | nil | lazy { project_commits_path(project, id, ref_type: 'heads') } + 'commits' | nil | nil | lazy { project_commits_path(project, id) } + 'commits' | 'heads' | nil | lazy { project_commits_path(project, id, ref_type: 'heads') } 'commits' | nil | 'foo/bar' | lazy { project_commits_path(project, id_and_path) } - nil | nil | nil | lazy { project_commits_path(project, id) } - nil | 'heads' | nil | lazy { project_commits_path(project, id, ref_type: 'heads') } + nil | nil | nil | lazy { project_commits_path(project, id) } + nil | 'heads' | nil | lazy { project_commits_path(project, id, ref_type: 'heads') } nil | nil | 'foo/bar' | lazy { project_commits_path(project, id_and_path) } end diff --git a/spec/controllers/projects/registry/repositories_controller_spec.rb b/spec/controllers/projects/registry/repositories_controller_spec.rb index 834fdddd583..a07a3641edf 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' -RSpec.describe Projects::Registry::RepositoriesController do +RSpec.describe Projects::Registry::RepositoriesController, feature_category: :container_registry do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :private) } @@ -103,8 +103,6 @@ RSpec.describe Projects::Registry::RepositoriesController do end it 'marks the repository as delete_scheduled' do - expect(DeleteContainerRepositoryWorker).not_to receive(:perform_async).with(user.id, repository.id) - expect { delete_repository(repository) } .to change { repository.reload.status }.from(nil).to('delete_scheduled') @@ -113,8 +111,6 @@ RSpec.describe Projects::Registry::RepositoriesController do end it 'tracks the event', :snowplow do - allow(DeleteContainerRepositoryWorker).to receive(:perform_async).with(user.id, repository.id) - delete_repository(repository) expect_snowplow_event(category: anything, action: 'delete_repository') diff --git a/spec/controllers/projects/runners_controller_spec.rb b/spec/controllers/projects/runners_controller_spec.rb index d6816bd49af..3602a2df959 100644 --- a/spec/controllers/projects/runners_controller_spec.rb +++ b/spec/controllers/projects/runners_controller_spec.rb @@ -17,7 +17,6 @@ RSpec.describe Projects::RunnersController, feature_category: :runner_fleet do before do sign_in(user) - project.add_maintainer(user) end describe '#new' do @@ -29,7 +28,7 @@ RSpec.describe Projects::RunnersController, feature_category: :runner_fleet do end context 'when user is maintainer' do - before do + before_all do project.add_maintainer(user) end @@ -42,7 +41,7 @@ RSpec.describe Projects::RunnersController, feature_category: :runner_fleet do end context 'when user is not maintainer' do - before do + before_all do project.add_developer(user) end @@ -55,15 +54,19 @@ RSpec.describe Projects::RunnersController, feature_category: :runner_fleet do end describe '#register' do - subject(:register) { get :register, params: { namespace_id: project.namespace, project_id: project, id: new_runner } } + subject(:register) do + get :register, params: { namespace_id: project.namespace, project_id: project, id: new_runner } + end context 'when user is maintainer' do - before do + before_all do project.add_maintainer(user) end context 'when runner can be registered after creation' do - let_it_be(:new_runner) { create(:ci_runner, :project, projects: [project], registration_type: :authenticated_user) } + let_it_be(:new_runner) do + create(:ci_runner, :project, projects: [project], registration_type: :authenticated_user) + end it 'renders a :register template' do register @@ -85,12 +88,14 @@ RSpec.describe Projects::RunnersController, feature_category: :runner_fleet do end context 'when user is not maintainer' do - before do + before_all do project.add_developer(user) end context 'when runner can be registered after creation' do - let_it_be(:new_runner) { create(:ci_runner, :project, projects: [project], registration_type: :authenticated_user) } + let_it_be(:new_runner) do + create(:ci_runner, :project, projects: [project], registration_type: :authenticated_user) + end it 'returns :not_found' do register @@ -102,6 +107,10 @@ RSpec.describe Projects::RunnersController, feature_category: :runner_fleet do end describe '#update' do + before_all do + project.add_maintainer(user) + end + it 'updates the runner and ticks the queue' do new_desc = runner.description.swapcase @@ -117,6 +126,10 @@ RSpec.describe Projects::RunnersController, feature_category: :runner_fleet do end describe '#destroy' do + before_all do + project.add_maintainer(user) + end + it 'destroys the runner' do expect_next_instance_of(Ci::Runners::UnregisterRunnerService, runner, user) do |service| expect(service).to receive(:execute).once.and_call_original @@ -130,6 +143,10 @@ RSpec.describe Projects::RunnersController, feature_category: :runner_fleet do end describe '#resume' do + before_all do + project.add_maintainer(user) + end + it 'marks the runner as active and ticks the queue' do runner.update!(active: false) @@ -145,6 +162,10 @@ RSpec.describe Projects::RunnersController, feature_category: :runner_fleet do end describe '#pause' do + before_all do + project.add_maintainer(user) + end + it 'marks the runner as inactive and ticks the queue' do runner.update!(active: true) @@ -160,9 +181,14 @@ RSpec.describe Projects::RunnersController, feature_category: :runner_fleet do end describe '#toggle_shared_runners' do + let(:user) { create(:user) } let(:group) { create(:group) } let(:project) { create(:project, group: group) } + before do + project.add_maintainer(user) # rubocop: disable RSpec/BeforeAllRoleAssignment + end + it 'toggles shared_runners_enabled when the group allows shared runners' do project.update!(shared_runners_enabled: true) @@ -196,7 +222,8 @@ RSpec.describe Projects::RunnersController, feature_category: :runner_fleet do expect(response).to have_gitlab_http_status(:unauthorized) expect(project.shared_runners_enabled).to eq(false) - expect(json_response['error']).to eq('Shared runners enabled cannot be enabled because parent group does not allow it') + expect(json_response['error']) + .to eq('Shared runners enabled cannot be enabled because parent group does not allow it') end end end diff --git a/spec/controllers/projects/settings/ci_cd_controller_spec.rb b/spec/controllers/projects/settings/ci_cd_controller_spec.rb index 63c870eb133..b27b4e6fe19 100644 --- a/spec/controllers/projects/settings/ci_cd_controller_spec.rb +++ b/spec/controllers/projects/settings/ci_cd_controller_spec.rb @@ -100,15 +100,15 @@ RSpec.describe Projects::Settings::CiCdController, feature_category: :continuous show # warmup # with one tag - create(:ci_runner, :instance, tag_list: %w(shared_runner)) - create(:ci_runner, :project, projects: [other_project], tag_list: %w(project_runner)) - create(:ci_runner, :group, groups: [group], tag_list: %w(group_runner)) + create(:ci_runner, :instance, tag_list: %w[shared_runner]) + create(:ci_runner, :project, projects: [other_project], tag_list: %w[project_runner]) + create(:ci_runner, :group, groups: [group], tag_list: %w[group_runner]) control = ActiveRecord::QueryRecorder.new { show } # with several tags - create(:ci_runner, :instance, tag_list: %w(shared_runner tag2 tag3)) - create(:ci_runner, :project, projects: [other_project], tag_list: %w(project_runner tag2 tag3)) - create(:ci_runner, :group, groups: [group], tag_list: %w(group_runner tag2 tag3)) + create(:ci_runner, :instance, tag_list: %w[shared_runner tag2 tag3]) + create(:ci_runner, :project, projects: [other_project], tag_list: %w[project_runner tag2 tag3]) + create(:ci_runner, :group, groups: [group], tag_list: %w[group_runner tag2 tag3]) expect { show }.not_to exceed_query_limit(control) end diff --git a/spec/controllers/projects/work_items_controller_spec.rb b/spec/controllers/projects/work_items_controller_spec.rb index e0f61a4977b..fc5ac77c96c 100644 --- a/spec/controllers/projects/work_items_controller_spec.rb +++ b/spec/controllers/projects/work_items_controller_spec.rb @@ -34,10 +34,10 @@ RSpec.describe Projects::WorkItemsController, feature_category: :team_planning d end end - describe 'GET index' do + describe 'GET show' do specify do expect( - get(:index, params: { namespace_id: project.namespace, project_id: project, work_items_path: work_item.id }) + get(:show, params: { namespace_id: project.namespace, project_id: project, iid: work_item.iid }) ).to have_request_urgency(:low) end end diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 7d7bebb7106..dea359e8fee 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -1368,7 +1368,7 @@ RSpec.describe ProjectsController, feature_category: :groups_and_projects do it 'renders json in a correct format' do post :preview_markdown, params: { namespace_id: public_project.namespace, id: public_project, text: '*Markdown* text' } - expect(json_response.keys).to match_array(%w(body references)) + expect(json_response.keys).to match_array(%w[body references]) end context 'when not authorized' do diff --git a/spec/controllers/registrations/welcome_controller_spec.rb b/spec/controllers/registrations/welcome_controller_spec.rb deleted file mode 100644 index 0bac52c8dca..00000000000 --- a/spec/controllers/registrations/welcome_controller_spec.rb +++ /dev/null @@ -1,119 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Registrations::WelcomeController, feature_category: :system_access do - let(:user) { create(:user) } - - describe '#show' do - subject(:show) { get :show } - - context 'without a signed in user' do - it { is_expected.to redirect_to new_user_registration_path } - end - - context 'when setup_for_company is not set' do - before do - sign_in(user) - end - - it { is_expected.to render_template(:show) } - - render_views - - it 'has the expected submission url' do - show - - expect(response.body).to include("action=\"#{users_sign_up_welcome_path}\"") - end - end - - context 'when setup_for_company is set' do - before do - user.update!(setup_for_company: false) - sign_in(user) - end - - it { is_expected.to redirect_to(dashboard_projects_path) } - end - - context 'when 2FA is required from group' do - before do - user = create(:user, require_two_factor_authentication_from_group: true) - sign_in(user) - end - - it 'does not perform a redirect' do - expect(subject).not_to redirect_to(profile_two_factor_auth_path) - end - end - - context 'when welcome step is completed' do - before do - user.update!(setup_for_company: true) - end - - context 'when user is confirmed' do - before do - sign_in(user) - end - - it { is_expected.to redirect_to dashboard_projects_path } - end - - context 'when user is not confirmed' do - before do - stub_application_setting_enum('email_confirmation_setting', 'hard') - - sign_in(user) - - user.update!(confirmed_at: nil) - end - - it { is_expected.to redirect_to user_session_path } - end - end - end - - describe '#update' do - subject(:update) do - patch :update, params: { user: { role: 'software_developer', setup_for_company: 'false' } } - end - - context 'without a signed in user' do - it { is_expected.to redirect_to new_user_registration_path } - end - - context 'with a signed in user' do - before do - sign_in(user) - end - - it { is_expected.to redirect_to(dashboard_projects_path) } - - context 'when the new user already has any accepted group membership' do - let!(:member1) { create(:group_member, user: user) } - - it 'redirects to the group activity page' do - expect(subject).to redirect_to(activity_group_path(member1.source)) - end - - context 'when the new user already has more than 1 accepted group membership' do - it 'redirects to the most recent membership group activity page' do - member2 = create(:group_member, user: user) - - expect(subject).to redirect_to(activity_group_path(member2.source)) - end - end - - context 'when the member has an orphaned source at the time of the welcome' do - it 'redirects to the project dashboard page' do - member1.source.delete - - expect(subject).to redirect_to(dashboard_projects_path) - end - end - end - end - end -end diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 9aa8a2ae605..156479c7044 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -46,7 +46,7 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do subject(:post_create) { post(:create, params: user_params, session: session_params) } - context '`blocked_pending_approval` state' do + context 'with `blocked_pending_approval` state' do context 'when the `require_admin_approval_after_user_signup` setting is turned on' do before do stub_application_setting(require_admin_approval_after_user_signup: true) @@ -82,7 +82,7 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do subject end - context 'email confirmation' do + context 'for email confirmation' do context 'when email confirmation setting is set to `hard`' do before do stub_application_setting_enum('email_confirmation_setting', 'hard') @@ -95,7 +95,7 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do end end - context 'audit events' do + context 'with audit events' do context 'when not licensed' do before do stub_licensed_features(admin_audit_log: false) @@ -129,7 +129,7 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do subject end - context 'email confirmation' do + context 'with email confirmation' do context 'when email confirmation setting is set to `hard`' do before do stub_application_setting_enum('email_confirmation_setting', 'hard') @@ -145,7 +145,7 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do end end - context 'private profile' do + context 'with private profile' do context 'when the `user_defaults_to_private_profile` setting is turned on' do before do stub_application_setting(user_defaults_to_private_profile: true) @@ -160,7 +160,7 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do end end - context 'email confirmation' do + context 'with email confirmation' do before do stub_feature_flags(identity_verification: false) end @@ -209,7 +209,7 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do context 'when member exists from the session key value' do it 'tracks the invite acceptance' do - subject + post_create expect_snowplow_event( category: 'RegistrationsController', @@ -299,7 +299,7 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do it 'authenticates the user and sends a confirmation email' do expect { subject }.to have_enqueued_mail(DeviseMailer, :confirmation_instructions) expect(controller.current_user).to be_present - expect(response).to redirect_to(users_sign_up_welcome_path) + expect(response).to redirect_to(dashboard_projects_path) end it 'does not track an almost there redirect' do @@ -312,6 +312,11 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do ) end + it_behaves_like Onboarding::Redirectable do + let(:email) { user_params.dig(:user, :email) } + let(:session_params) { { invite_email: email } } + end + context 'when invite email matches email used on registration' do let(:session_params) { { invite_email: user_params.dig(:user, :email) } } @@ -375,10 +380,10 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do end end - it 'redirects to the welcome page when the reCAPTCHA is solved' do + it 'redirects to the dashboard projects page when the reCAPTCHA is solved' do subject - expect(response).to redirect_to(users_sign_up_welcome_path) + expect(response).to redirect_to(dashboard_projects_path) end end @@ -430,7 +435,7 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do describe 'timestamp spam detection' do let(:auth_log_message) { 'Invisible_Captcha_Timestamp_Request' } - context 'the sign up form has been submitted without the invisible_captcha_timestamp parameter' do + context 'when the sign up form has been submitted without the invisible_captcha_timestamp parameter' do let(:session_params) { nil } it 'logs the request, refuses to create an account and displays a flash alert' do @@ -446,7 +451,7 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do end end - context 'the sign up form has been submitted too quickly' do + context 'when the sign up form has been submitted too quickly' do let(:submit_time) { form_rendered_time } it 'logs the request, refuses to create an account and displays a flash alert' do @@ -464,7 +469,7 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do end end - context 'terms of service' do + context 'with terms of service' do context 'when terms are enforced' do before do enforce_terms @@ -674,7 +679,7 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do expect(response).to redirect_to new_user_session_path end - context 'user requires password confirmation' do + context 'when user requires password confirmation' do it 'fails if password confirmation is not provided' do post :destroy @@ -694,7 +699,7 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do end end - context 'user does not require password confirmation' do + context 'when user does not require password confirmation' do before do stub_application_setting(password_authentication_enabled_for_web: false) stub_application_setting(password_authentication_enabled_for_git: false) @@ -719,8 +724,8 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do end end - context 'prerequisites for account deletion' do - context 'solo-owned groups' do + context 'for prerequisites for account deletion' do + context 'with solo-owned groups' do let(:group) { create(:group) } context 'if the user is the sole owner of at least one group' do diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index 9771141a955..94aedf463e9 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -551,7 +551,7 @@ RSpec.describe SearchController, feature_category: :global_search do expect(payload[:metadata]['meta.search.force_search_results']).to eq('true') expect(payload[:metadata]['meta.search.filters.confidential']).to eq('true') expect(payload[:metadata]['meta.search.filters.state']).to eq('true') - expect(payload[:metadata]['meta.search.project_ids']).to eq(%w(456 789)) + expect(payload[:metadata]['meta.search.project_ids']).to eq(%w[456 789]) expect(payload[:metadata]['meta.search.type']).to eq('basic') expect(payload[:metadata]['meta.search.level']).to eq('global') expect(payload[:metadata]['meta.search.filters.language']).to eq('ruby') @@ -562,7 +562,7 @@ RSpec.describe SearchController, feature_category: :global_search do search: 'hello world', group_id: '123', project_id: '456', - project_ids: %w(456 789), + project_ids: %w[456 789], confidential: true, include_archived: true, state: true, diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index ce9703753cf..85248b6fa6c 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -195,10 +195,6 @@ RSpec.describe SessionsController, feature_category: :system_access do end context 'with reCAPTCHA' do - before do - stub_feature_flags(arkose_labs_login_challenge: false) - end - def unsuccesful_login(user_params, sesion_params: {}) # Without this, `verify_recaptcha` arbitrarily returns true in test env Recaptcha.configuration.skip_verify_env.delete('test') diff --git a/spec/controllers/snippets_controller_spec.rb b/spec/controllers/snippets_controller_spec.rb index 18b2d3b14ec..b33687df2ef 100644 --- a/spec/controllers/snippets_controller_spec.rb +++ b/spec/controllers/snippets_controller_spec.rb @@ -452,7 +452,7 @@ RSpec.describe SnippetsController do post :preview_markdown, params: { id: public_snippet, text: '*Markdown* text' } - expect(json_response.keys).to match_array(%w(body references)) + expect(json_response.keys).to match_array(%w[body references]) end end end |