diff options
Diffstat (limited to 'spec/requests/projects')
9 files changed, 162 insertions, 35 deletions
diff --git a/spec/requests/projects/cycle_analytics_events_spec.rb b/spec/requests/projects/cycle_analytics_events_spec.rb index 65540f86d34..370febf82ff 100644 --- a/spec/requests/projects/cycle_analytics_events_spec.rb +++ b/spec/requests/projects/cycle_analytics_events_spec.rb @@ -9,7 +9,7 @@ RSpec.describe 'value stream analytics events' do let(:project) { create(:project, :repository, public_builds: false) } let(:issue) { create(:issue, project: project, created_at: 2.days.ago) } - describe 'GET /:namespace/:project/value_stream_analytics/events/issues' do + describe 'GET /:namespace/:project/value_stream_analytics/events/issues', :sidekiq_inline do let(:first_issue_iid) { project.issues.sort_by_attribute(:created_desc).pick(:iid).to_s } let(:first_mr_iid) { project.merge_requests.sort_by_attribute(:created_desc).pick(:iid).to_s } @@ -65,7 +65,7 @@ RSpec.describe 'value stream analytics events' do expect(json_response['events'].first['iid']).to eq(first_mr_iid) end - it 'lists the staging events', :sidekiq_inline do + it 'lists the staging events' do get project_cycle_analytics_staging_path(project, format: :json) expect(json_response['events']).not_to be_empty diff --git a/spec/requests/projects/google_cloud/deployments_controller_spec.rb b/spec/requests/projects/google_cloud/deployments_controller_spec.rb index ad6a3912e0b..c777e8c1f69 100644 --- a/spec/requests/projects/google_cloud/deployments_controller_spec.rb +++ b/spec/requests/projects/google_cloud/deployments_controller_spec.rb @@ -83,7 +83,7 @@ RSpec.describe Projects::GoogleCloud::DeploymentsController do end it 'renders template' do - get "#{project_google_cloud_deployments_path(project)}" + get project_google_cloud_deployments_path(project).to_s expect(response).to render_template(:index) @@ -98,7 +98,7 @@ RSpec.describe Projects::GoogleCloud::DeploymentsController do end describe 'Authorized GET project/-/google_cloud/deployments/cloud_run', :snowplow do - let_it_be(:url) { "#{project_google_cloud_deployments_cloud_run_path(project)}" } + let_it_be(:url) { project_google_cloud_deployments_cloud_run_path(project).to_s } before do sign_in(user_maintainer) @@ -188,7 +188,7 @@ RSpec.describe Projects::GoogleCloud::DeploymentsController do end describe 'Authorized GET project/-/google_cloud/deployments/cloud_storage', :snowplow do - let_it_be(:url) { "#{project_google_cloud_deployments_cloud_storage_path(project)}" } + let_it_be(:url) { project_google_cloud_deployments_cloud_storage_path(project).to_s } before do allow_next_instance_of(GoogleApi::CloudPlatform::Client) do |client| diff --git a/spec/requests/projects/google_cloud/service_accounts_controller_spec.rb b/spec/requests/projects/google_cloud/service_accounts_controller_spec.rb index 133c6f9153d..d91e5a4f068 100644 --- a/spec/requests/projects/google_cloud/service_accounts_controller_spec.rb +++ b/spec/requests/projects/google_cloud/service_accounts_controller_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Projects::GoogleCloud::ServiceAccountsController do let_it_be(:project) { create(:project, :public) } describe 'GET index', :snowplow do - let_it_be(:url) { "#{project_google_cloud_service_accounts_path(project)}" } + let_it_be(:url) { project_google_cloud_service_accounts_path(project).to_s } let_it_be(:user_guest) { create(:user) } let_it_be(:user_developer) { create(:user) } diff --git a/spec/requests/projects/issue_links_controller_spec.rb b/spec/requests/projects/issue_links_controller_spec.rb index 81fd1adb1fd..e5f40625cfa 100644 --- a/spec/requests/projects/issue_links_controller_spec.rb +++ b/spec/requests/projects/issue_links_controller_spec.rb @@ -28,12 +28,28 @@ RSpec.describe Projects::IssueLinksController do context 'when linked issue is a task' do let(:issue_b) { create :issue, :task, project: project } - it 'returns a work item path for the linked task' do + context 'when the use_iid_in_work_items_path feature flag is disabled' do + before do + stub_feature_flags(use_iid_in_work_items_path: false) + end + + it 'returns a work item path for the linked task' do + get namespace_project_issue_links_path(issue_links_params) + + expect(json_response.count).to eq(1) + expect(json_response.first).to include( + 'path' => project_work_items_path(issue_b.project, issue_b.id), + 'type' => 'TASK' + ) + end + end + + it 'returns a work item path for the linked task using the iid in the path' do get namespace_project_issue_links_path(issue_links_params) expect(json_response.count).to eq(1) expect(json_response.first).to include( - 'path' => project_work_items_path(issue_b.project, issue_b.id), + 'path' => project_work_items_path(issue_b.project, issue_b.iid, iid_path: true), 'type' => 'TASK' ) end diff --git a/spec/requests/projects/merge_requests/context_commit_diffs_spec.rb b/spec/requests/projects/merge_requests/context_commit_diffs_spec.rb index c859e91e21a..ec65e8cf11e 100644 --- a/spec/requests/projects/merge_requests/context_commit_diffs_spec.rb +++ b/spec/requests/projects/merge_requests/context_commit_diffs_spec.rb @@ -35,7 +35,7 @@ RSpec.describe 'Merge Requests Context Commit Diffs' do commit: nil, diff_view: :inline, merge_ref_head_diff: nil, - allow_tree_conflicts: true, + merge_conflicts_in_diff: true, pagination_data: { total_pages: nil }.merge(pagination_data) diff --git a/spec/requests/projects/merge_requests/diffs_spec.rb b/spec/requests/projects/merge_requests/diffs_spec.rb index 9f0b9a9cb1b..12990b54617 100644 --- a/spec/requests/projects/merge_requests/diffs_spec.rb +++ b/spec/requests/projects/merge_requests/diffs_spec.rb @@ -33,7 +33,7 @@ RSpec.describe 'Merge Requests Diffs' do commit: nil, diff_view: :inline, merge_ref_head_diff: nil, - allow_tree_conflicts: true, + merge_conflicts_in_diff: true, pagination_data: { total_pages: nil }.merge(pagination_data) @@ -80,6 +80,20 @@ RSpec.describe 'Merge Requests Diffs' do expect(response).to have_gitlab_http_status(:not_modified) end + context 'with check_etags_diffs_batch_before_write_cache flag turned off' do + before do + stub_feature_flags(check_etags_diffs_batch_before_write_cache: false) + end + + it 'does not serialize diffs' do + expect(PaginatedDiffSerializer).not_to receive(:new) + + go(headers: headers, page: 0, per_page: 5) + + expect(response).to have_gitlab_http_status(:not_modified) + end + end + context 'with the different user' do let(:another_user) { create(:user) } let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch } @@ -114,7 +128,7 @@ RSpec.describe 'Merge Requests Diffs' do context 'with disabled display_merge_conflicts_in_diff feature' do let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch } - let(:expected_options) { collection_arguments(total_pages: 20).merge(allow_tree_conflicts: false) } + let(:expected_options) { collection_arguments(total_pages: 20).merge(merge_conflicts_in_diff: false) } before do stub_feature_flags(display_merge_conflicts_in_diff: false) diff --git a/spec/requests/projects/ml/experiments_controller_spec.rb b/spec/requests/projects/ml/experiments_controller_spec.rb new file mode 100644 index 00000000000..67a2fe47dc8 --- /dev/null +++ b/spec/requests/projects/ml/experiments_controller_spec.rb @@ -0,0 +1,100 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Projects::Ml::ExperimentsController do + let_it_be(:project_with_feature) { create(:project, :repository) } + let_it_be(:user) { project_with_feature.first_owner } + let_it_be(:project_without_feature) do + create(:project, :repository).tap { |p| p.add_developer(user) } + end + + let_it_be(:experiment) do + create(:ml_experiments, project: project_with_feature, user: user).tap do |e| + create(:ml_candidates, experiment: e, user: user) + end + end + + let(:params) { basic_params } + let(:ff_value) { true } + let(:threshold) { 4 } + let(:project) { project_with_feature } + let(:basic_params) { { namespace_id: project.namespace.to_param, project_id: project } } + + before do + stub_feature_flags(ml_experiment_tracking: false) + stub_feature_flags(ml_experiment_tracking: project_with_feature) if ff_value + + sign_in(user) + end + + shared_examples '404 if feature flag disabled' do + context 'when :ml_experiment_tracking disabled' do + let(:ff_value) { false } + + it 'is 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + describe 'GET index' do + before do + list_experiments + end + + it 'renders the template' do + expect(response).to render_template('projects/ml/experiments/index') + end + + it 'does not perform N+1 sql queries' do + control_count = ActiveRecord::QueryRecorder.new { list_experiments } + + create_list(:ml_experiments, 2, project: project, user: user) + + expect { list_experiments }.not_to exceed_all_query_limit(control_count).with_threshold(threshold) + end + + context 'when :ml_experiment_tracking is disabled for the project' do + let(:project) { project_without_feature } + + it 'responds with a 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + + it_behaves_like '404 if feature flag disabled' + end + + describe 'GET show' do + let(:params) { basic_params.merge(id: experiment.iid) } + + before do + show_experiment + end + + it 'renders the template' do + expect(response).to render_template('projects/ml/experiments/show') + end + + it 'does not perform N+1 sql queries' do + control_count = ActiveRecord::QueryRecorder.new { show_experiment } + + create_list(:ml_candidates, 2, :with_metrics_and_params, experiment: experiment) + + expect { show_experiment }.not_to exceed_all_query_limit(control_count).with_threshold(threshold) + end + + it_behaves_like '404 if feature flag disabled' + end + + private + + def show_experiment + get project_ml_experiment_path(project, experiment.iid), params: params + end + + def list_experiments + get project_ml_experiments_path(project), params: params + end +end diff --git a/spec/requests/projects/settings/access_tokens_controller_spec.rb b/spec/requests/projects/settings/access_tokens_controller_spec.rb index 48114834c65..17389cdcce7 100644 --- a/spec/requests/projects/settings/access_tokens_controller_spec.rb +++ b/spec/requests/projects/settings/access_tokens_controller_spec.rb @@ -6,11 +6,11 @@ RSpec.describe Projects::Settings::AccessTokensController do let_it_be(:user) { create(:user) } let_it_be(:group) { create(:group) } let_it_be(:resource) { create(:project, group: group) } - let_it_be(:bot_user) { create(:user, :project_bot) } + let_it_be(:access_token_user) { create(:user, :project_bot) } before_all do resource.add_maintainer(user) - resource.add_maintainer(bot_user) + resource.add_maintainer(access_token_user) end before do @@ -28,13 +28,24 @@ RSpec.describe Projects::Settings::AccessTokensController do end describe 'GET /:namespace/:project/-/settings/access_tokens' do - subject do + let(:get_access_tokens) do get project_settings_access_tokens_path(resource) response end + let(:get_access_tokens_json) do + get project_settings_access_tokens_path(resource), params: { format: :json } + response + end + + subject(:get_access_tokens_with_page) do + get project_settings_access_tokens_path(resource), params: { page: 1 } + response + end + it_behaves_like 'feature unavailable' it_behaves_like 'GET resource access tokens available' + it_behaves_like 'GET access tokens are paginated and ordered' end describe 'POST /:namespace/:project/-/settings/access_tokens' do @@ -78,7 +89,7 @@ RSpec.describe Projects::Settings::AccessTokensController do end describe 'PUT /:namespace/:project/-/settings/access_tokens/:id', :sidekiq_inline do - let(:resource_access_token) { create(:personal_access_token, user: bot_user) } + let(:resource_access_token) { create(:personal_access_token, user: access_token_user) } subject do put revoke_project_settings_access_token_path(resource, resource_access_token) @@ -90,17 +101,17 @@ RSpec.describe Projects::Settings::AccessTokensController do end describe '#index' do - let_it_be(:resource_access_tokens) { create_list(:personal_access_token, 3, user: bot_user) } + let_it_be(:resource_access_tokens) { create_list(:personal_access_token, 3, user: access_token_user) } before do get project_settings_access_tokens_path(resource) end it 'includes details of the active project access tokens' do - active_resource_access_tokens = + active_access_tokens = ::ProjectAccessTokenSerializer.new.represent(resource_access_tokens.reverse, project: resource) - expect(assigns(:active_resource_access_tokens).to_json).to eq(active_resource_access_tokens.to_json) + expect(assigns(:active_access_tokens).to_json).to eq(active_access_tokens.to_json) end end end diff --git a/spec/requests/projects/work_items_spec.rb b/spec/requests/projects/work_items_spec.rb index e6365a3824a..4d7acc73d4f 100644 --- a/spec/requests/projects/work_items_spec.rb +++ b/spec/requests/projects/work_items_spec.rb @@ -15,24 +15,10 @@ RSpec.describe 'Work Items' do sign_in(developer) end - context 'when the work_items feature flag is enabled' do - it 'renders index' do - get project_work_items_url(work_item.project, work_items_path: work_item.id) + it 'renders index' do + get project_work_items_url(work_item.project, work_items_path: work_item.id) - expect(response).to have_gitlab_http_status(:ok) - end - end - - context 'when the work_items feature flag is disabled' do - before do - stub_feature_flags(work_items: false) - end - - it 'returns 404' do - get project_work_items_url(work_item.project, work_items_path: work_item.id) - - expect(response).to have_gitlab_http_status(:not_found) - end + expect(response).to have_gitlab_http_status(:ok) end end end |