diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/controllers/projects | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/controllers/projects')
15 files changed, 214 insertions, 103 deletions
diff --git a/spec/controllers/projects/blob_controller_spec.rb b/spec/controllers/projects/blob_controller_spec.rb index 9493215247a..53efcc65066 100644 --- a/spec/controllers/projects/blob_controller_spec.rb +++ b/spec/controllers/projects/blob_controller_spec.rb @@ -5,7 +5,8 @@ require 'spec_helper' RSpec.describe Projects::BlobController do include ProjectForksHelper - let(:project) { create(:project, :public, :repository) } + let(:project) { create(:project, :public, :repository, previous_default_branch: previous_default_branch) } + let(:previous_default_branch) { nil } describe "GET show" do def request @@ -42,6 +43,20 @@ RSpec.describe Projects::BlobController do it { is_expected.to respond_with(:not_found) } end + context "renamed default branch, valid file" do + let(:id) { 'old-default-branch/README.md' } + let(:previous_default_branch) { 'old-default-branch' } + + it { is_expected.to redirect_to("/#{project.full_path}/-/blob/#{project.default_branch}/README.md") } + end + + context "renamed default branch, invalid file" do + let(:id) { 'old-default-branch/invalid-path.rb' } + let(:previous_default_branch) { 'old-default-branch' } + + it { is_expected.to redirect_to("/#{project.full_path}/-/blob/#{project.default_branch}/invalid-path.rb") } + end + context "binary file" do let(:id) { 'binary-encoding/encoding/binary-1.bin' } diff --git a/spec/controllers/projects/commit_controller_spec.rb b/spec/controllers/projects/commit_controller_spec.rb index c650d145bef..16bb33e95c8 100644 --- a/spec/controllers/projects/commit_controller_spec.rb +++ b/spec/controllers/projects/commit_controller_spec.rb @@ -483,7 +483,7 @@ RSpec.describe Projects::CommitController do end context 'when rendering a JSON format' do - it 'responds with serialized pipelines' do + it 'responds with serialized pipelines', :aggregate_failures do get_pipelines(id: commit.id, format: :json) expect(response).to be_ok @@ -491,6 +491,26 @@ RSpec.describe Projects::CommitController do expect(json_response['count']['all']).to eq 1 expect(response).to include_pagination_headers end + + context 'with pagination' do + let!(:extra_pipeline) { create(:ci_pipeline, project: project, ref: project.default_branch, sha: commit.sha, status: :running) } + + it 'paginates the result when ref is blank' do + allow(Ci::Pipeline).to receive(:default_per_page).and_return(1) + + get_pipelines(id: commit.id, format: :json) + + expect(json_response['pipelines'].count).to eq(1) + end + + it 'paginates the result when ref is present' do + allow(Ci::Pipeline).to receive(:default_per_page).and_return(1) + + get_pipelines(id: commit.id, ref: project.default_branch, format: :json) + + expect(json_response['pipelines'].count).to eq(1) + end + end end end end diff --git a/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb b/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb index c78b838d0df..55ab0f0eefa 100644 --- a/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb +++ b/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb @@ -109,7 +109,7 @@ RSpec.describe Projects::DesignManagement::Designs::RawImagesController do context 'when sha is nil' do let(:sha) { nil } - let(:expected_ref) { 'master' } + let(:expected_ref) { project.design_repository.root_ref } it_behaves_like 'a successful request for sha' end @@ -147,7 +147,7 @@ RSpec.describe Projects::DesignManagement::Designs::RawImagesController do let(:file) { fixture_file_upload('spec/fixtures/dk.png', '`/png') } let(:lfs_pointer) { Gitlab::Git::LfsPointerFile.new(file.read) } let(:design) { create(:design, :with_lfs_file, file: lfs_pointer.pointer, issue: issue) } - let(:lfs_oid) { project.design_repository.blob_at('HEAD', design.full_path).lfs_oid } + let(:lfs_oid) { project.design_repository.blob_at(design.repository.root_ref, design.full_path).lfs_oid } let(:filepath) { design.full_path } end end diff --git a/spec/controllers/projects/import/jira_controller_spec.rb b/spec/controllers/projects/import/jira_controller_spec.rb index 37a7fce0c23..5288c0fcf21 100644 --- a/spec/controllers/projects/import/jira_controller_spec.rb +++ b/spec/controllers/projects/import/jira_controller_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Projects::Import::JiraController do def ensure_correct_config sign_in(user) project.add_maintainer(user) - stub_jira_service_test + stub_jira_integration_test end shared_examples 'redirect with error' do |error| @@ -54,8 +54,8 @@ RSpec.describe Projects::Import::JiraController do context 'when loged user is a developer' do before do - create(:jira_service, project: project) - stub_jira_service_test + create(:jira_integration, project: project) + stub_jira_integration_test sign_in(user) project.add_developer(user) @@ -72,7 +72,7 @@ RSpec.describe Projects::Import::JiraController do it_behaves_like 'users without permissions' - context 'jira service configuration' do + context 'jira integration configuration' do before do sign_in(user) project.add_maintainer(user) @@ -80,14 +80,14 @@ RSpec.describe Projects::Import::JiraController do context 'when Jira service is not enabled for the project' do it 'does not query Jira service' do - expect(project).not_to receive(:jira_service) + expect(project).not_to receive(:jira_integration) end it_behaves_like 'template with no message' end context 'when Jira service is not configured correctly for the project' do - let_it_be(:jira_service) { create(:jira_service, project: project) } + let_it_be(:jira_integration) { create(:jira_integration, project: project) } before do WebMock.stub_request(:get, 'https://jira.example.com/rest/api/2/serverInfo') diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index 7569a18baeb..922ecb6052a 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -17,7 +17,7 @@ RSpec.describe Projects::IssuesController do before do sign_in(user) project.add_developer(user) - create(:jira_service, project: project) + create(:jira_integration, project: project) end context 'when GitLab issues disabled' do @@ -1016,10 +1016,13 @@ RSpec.describe Projects::IssuesController do let(:spammy_title) { 'Whatever' } let!(:spam_logs) { create_list(:spam_log, 2, user: user, title: spammy_title) } + before do + request.headers['X-GitLab-Captcha-Response'] = 'a-valid-captcha-response' + request.headers['X-GitLab-Spam-Log-Id'] = spam_logs.last.id + end + def update_verified_issue - update_issue( - issue_params: { title: spammy_title }, - additional_params: { spam_log_id: spam_logs.last.id, 'g-recaptcha-response': true }) + update_issue(issue_params: { title: spammy_title }) end it 'returns 200 status' do @@ -1036,8 +1039,9 @@ RSpec.describe Projects::IssuesController do it 'does not mark spam log as recaptcha_verified when it does not belong to current_user' do spam_log = create(:spam_log) + request.headers['X-GitLab-Spam-Log-Id'] = spam_log.id - expect { update_issue(issue_params: { spam_log_id: spam_log.id, 'g-recaptcha-response': true }) } + expect { update_issue } .not_to change { SpamLog.last.recaptcha_verified } end end diff --git a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb index 4fcb63ac616..707d074b5c1 100644 --- a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb @@ -88,8 +88,6 @@ RSpec.describe Projects::MergeRequests::DiffsController do let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } before do - stub_feature_flags(diffs_gradual_load: false) - project.add_maintainer(user) sign_in(user) end @@ -474,8 +472,6 @@ RSpec.describe Projects::MergeRequests::DiffsController do diff_view: :inline, merge_ref_head_diff: nil, pagination_data: { - current_page: nil, - next_page: nil, total_pages: nil }.merge(pagination_data) } @@ -486,7 +482,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do namespace_id: project.namespace.to_param, project_id: project, id: merge_request.iid, - page: 1, + page: 0, per_page: 20, format: 'json' } @@ -517,7 +513,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do it_behaves_like 'serializes diffs with expected arguments' do let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch } - let(:expected_options) { collection_arguments(current_page: 1, total_pages: 1).merge(merge_ref_head_diff: false) } + let(:expected_options) { collection_arguments(total_pages: 20).merge(merge_ref_head_diff: false) } end it_behaves_like 'successful request' @@ -557,7 +553,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do it_behaves_like 'serializes diffs with expected arguments' do let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch } let(:expected_options) do - collection_arguments(current_page: 1, total_pages: 1) + collection_arguments(total_pages: 20) end end @@ -576,18 +572,18 @@ RSpec.describe Projects::MergeRequests::DiffsController do it_behaves_like 'serializes diffs with expected arguments' do let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch } - let(:expected_options) { collection_arguments(current_page: 1, total_pages: 1) } + let(:expected_options) { collection_arguments(total_pages: 20) } end it_behaves_like 'successful request' end context 'with smaller diff batch params' do - subject { go(page: 2, per_page: 5) } + subject { go(page: 5, per_page: 5) } it_behaves_like 'serializes diffs with expected arguments' do let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch } - let(:expected_options) { collection_arguments(current_page: 2, next_page: 3, total_pages: 4) } + let(:expected_options) { collection_arguments(total_pages: 20) } end it_behaves_like 'successful request' diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index d4c52e1c7ca..7b5a58fe2e5 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -860,6 +860,20 @@ RSpec.describe Projects::MergeRequestsController do end end end + + context 'with pagination' do + before do + create(:ci_pipeline, project: merge_request.source_project, ref: merge_request.source_branch, sha: merge_request.diff_head_sha) + end + + it 'paginates the result' do + allow(Ci::Pipeline).to receive(:default_per_page).and_return(1) + + get :pipelines, params: { namespace_id: project.namespace.to_param, project_id: project, id: merge_request.iid }, format: :json + + expect(json_response['pipelines'].count).to eq(1) + end + end end describe 'GET context commits' do diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index a80c5fa82f6..2379ff9fd98 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -66,6 +66,14 @@ RSpec.describe Projects::PipelinesController do expect(json_response['pipelines'][0]).not_to include('coverage') end + it 'paginates the result' do + allow(Ci::Pipeline).to receive(:default_per_page).and_return(2) + + get_pipelines_index_json + + check_pipeline_response(returned: 2, all: 6) + end + context 'when performing gitaly calls', :request_store do it 'limits the Gitaly requests' do # Isolate from test preparation (Repository#exists? is also cached in RequestStore) @@ -284,10 +292,6 @@ RSpec.describe Projects::PipelinesController do subject { project.namespace } - context 'pipeline_empty_state_templates experiment' do - it_behaves_like 'tracks assignment and records the subject', :pipeline_empty_state_templates, :namespace - end - context 'code_quality_walkthrough experiment' do it_behaves_like 'tracks assignment and records the subject', :code_quality_walkthrough, :namespace end diff --git a/spec/controllers/projects/prometheus/metrics_controller_spec.rb b/spec/controllers/projects/prometheus/metrics_controller_spec.rb index c7c3be20f29..5338b77bd08 100644 --- a/spec/controllers/projects/prometheus/metrics_controller_spec.rb +++ b/spec/controllers/projects/prometheus/metrics_controller_spec.rb @@ -141,7 +141,7 @@ RSpec.describe Projects::Prometheus::MetricsController do expect(flash[:notice]).to include('Metric was successfully added.') - expect(response).to redirect_to(edit_project_service_path(project, PrometheusService)) + expect(response).to redirect_to(edit_project_service_path(project, ::Integrations::Prometheus)) end end @@ -164,7 +164,7 @@ RSpec.describe Projects::Prometheus::MetricsController do it 'destroys the metric' do delete :destroy, params: project_params(id: metric.id) - expect(response).to redirect_to(edit_project_service_path(project, PrometheusService)) + expect(response).to redirect_to(edit_project_service_path(project, ::Integrations::Prometheus)) expect(PrometheusMetric.find_by(id: metric.id)).to be_nil end end diff --git a/spec/controllers/projects/runners_controller_spec.rb b/spec/controllers/projects/runners_controller_spec.rb index 39b45a7133c..70ff77d7ff0 100644 --- a/spec/controllers/projects/runners_controller_spec.rb +++ b/spec/controllers/projects/runners_controller_spec.rb @@ -111,7 +111,7 @@ RSpec.describe Projects::RunnersController do expect(response).to have_gitlab_http_status(:unauthorized) expect(project.shared_runners_enabled).to eq(false) - expect(json_response['error']).to eq('Cannot enable shared runners 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/service_hook_logs_controller_spec.rb b/spec/controllers/projects/service_hook_logs_controller_spec.rb index 040e59fc822..9caa4a06b44 100644 --- a/spec/controllers/projects/service_hook_logs_controller_spec.rb +++ b/spec/controllers/projects/service_hook_logs_controller_spec.rb @@ -27,6 +27,15 @@ RSpec.describe Projects::ServiceHookLogsController do specify do expect(response).to be_successful end + + it 'renders a 404 if the hook does not exist' do + log_params + integration.service_hook.destroy! + + subject + + expect(response).to have_gitlab_http_status(:not_found) + end end describe 'POST #retry' do @@ -37,5 +46,14 @@ RSpec.describe Projects::ServiceHookLogsController do expect_any_instance_of(described_class).to receive(:set_hook_execution_notice) expect(subject).to redirect_to(edit_project_service_path(project, integration)) end + + it 'renders a 404 if the hook does not exist' do + log_params + integration.service_hook.destroy! + + subject + + expect(response).to have_gitlab_http_status(:not_found) + end end end diff --git a/spec/controllers/projects/usage_ping_controller_spec.rb b/spec/controllers/projects/service_ping_controller_spec.rb index 9ace072d561..e6afaadc75f 100644 --- a/spec/controllers/projects/usage_ping_controller_spec.rb +++ b/spec/controllers/projects/service_ping_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::UsagePingController do +RSpec.describe Projects::ServicePingController do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } diff --git a/spec/controllers/projects/services_controller_spec.rb b/spec/controllers/projects/services_controller_spec.rb index f8474ab1082..baf3bde83bd 100644 --- a/spec/controllers/projects/services_controller_spec.rb +++ b/spec/controllers/projects/services_controller_spec.rb @@ -6,10 +6,12 @@ RSpec.describe Projects::ServicesController do include JiraServiceHelper include AfterNextHelpers - let(:project) { create(:project, :repository) } - let(:user) { create(:user) } - let(:service) { create(:jira_service, project: project) } - let(:service_params) { { username: 'username', password: 'password', url: 'http://example.com' } } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + let_it_be(:jira_integration) { create(:jira_integration, project: project) } + + let(:integration) { jira_integration } + let(:integration_params) { { username: 'username', password: 'password', url: 'http://example.com' } } before do sign_in(user) @@ -17,9 +19,9 @@ RSpec.describe Projects::ServicesController do end describe '#test' do - context 'when can_test? returns false' do + context 'when the integration is not testable' do it 'renders 404' do - allow_any_instance_of(Integration).to receive(:can_test?).and_return(false) + allow_any_instance_of(Integration).to receive(:testable?).and_return(false) put :test, params: project_params @@ -28,10 +30,10 @@ RSpec.describe Projects::ServicesController do end context 'when validations fail' do - let(:service_params) { { active: 'true', url: '' } } + let(:integration_params) { { active: 'true', url: '' } } it 'returns error messages in JSON response' do - put :test, params: project_params(service: service_params) + put :test, params: project_params(service: integration_params) expect(json_response['message']).to eq 'Validations failed.' expect(json_response['service_response']).to include "Url can't be blank" @@ -39,15 +41,17 @@ RSpec.describe Projects::ServicesController do end end - context 'success' do + context 'when successful' do context 'with empty project' do - let(:project) { create(:project) } + let_it_be(:project) { create(:project) } + + context 'with chat notification integration' do + let_it_be(:teams_integration) { project.create_microsoft_teams_integration(webhook: 'http://webhook.com') } - context 'with chat notification service' do - let(:service) { project.create_microsoft_teams_service(webhook: 'http://webhook.com') } + let(:integration) { teams_integration } it 'returns success' do - allow_any_instance_of(::MicrosoftTeams::Notifier).to receive(:ping).and_return(true) + allow_next(::MicrosoftTeams::Notifier).to receive(:ping).and_return(true) put :test, params: project_params @@ -56,28 +60,28 @@ RSpec.describe Projects::ServicesController do end it 'returns success' do - stub_jira_service_test + stub_jira_integration_test expect(Gitlab::HTTP).to receive(:get).with('/rest/api/2/serverInfo', any_args).and_call_original - put :test, params: project_params(service: service_params) + put :test, params: project_params(service: integration_params) expect(response).to be_successful end end it 'returns success' do - stub_jira_service_test + stub_jira_integration_test expect(Gitlab::HTTP).to receive(:get).with('/rest/api/2/serverInfo', any_args).and_call_original - put :test, params: project_params(service: service_params) + put :test, params: project_params(service: integration_params) expect(response).to be_successful end context 'when service is configured for the first time' do - let(:service_params) do + let(:integration_params) do { 'active' => '1', 'push_events' => '1', @@ -108,17 +112,17 @@ RSpec.describe Projects::ServicesController do def do_put put :test, params: project_params(id: 'buildkite', - service: service_params) + service: integration_params) end end end - context 'failure' do + context 'when unsuccessful' do it 'returns an error response when the integration test fails' do stub_request(:get, 'http://example.com/rest/api/2/serverInfo') .to_return(status: 404) - put :test, params: project_params(service: service_params) + put :test, params: project_params(service: integration_params) expect(response).to be_successful expect(json_response).to eq( @@ -130,7 +134,7 @@ RSpec.describe Projects::ServicesController do end context 'with the Slack integration' do - let_it_be(:service) { build(:slack_service) } + let_it_be(:integration) { build(:integrations_slack) } it 'returns an error response when the URL is blocked' do put :test, params: project_params(service: { webhook: 'http://127.0.0.1' }) @@ -163,17 +167,17 @@ RSpec.describe Projects::ServicesController do describe 'PUT #update' do describe 'as HTML' do - let(:service_params) { { active: true } } - let(:params) { project_params(service: service_params) } + let(:integration_params) { { active: true } } + let(:params) { project_params(service: integration_params) } let(:message) { 'Jira settings saved and active.' } - let(:redirect_url) { edit_project_service_path(project, service) } + let(:redirect_url) { edit_project_service_path(project, integration) } before do put :update, params: params end - shared_examples 'service update' do + shared_examples 'integration update' do it 'redirects to the correct url with a flash message' do expect(response).to redirect_to(redirect_url) expect(flash[:notice]).to eq(message) @@ -181,61 +185,61 @@ RSpec.describe Projects::ServicesController do end context 'when param `active` is set to true' do - let(:params) { project_params(service: service_params, redirect_to: redirect) } + let(:params) { project_params(service: integration_params, redirect_to: redirect) } context 'when redirect_to param is present' do let(:redirect) { '/redirect_here' } let(:redirect_url) { redirect } - it_behaves_like 'service update' + it_behaves_like 'integration update' end context 'when redirect_to is an external domain' do let(:redirect) { 'http://examle.com' } - it_behaves_like 'service update' + it_behaves_like 'integration update' end context 'when redirect_to param is an empty string' do let(:redirect) { '' } - it_behaves_like 'service update' + it_behaves_like 'integration update' end end context 'when param `active` is set to false' do - let(:service_params) { { active: false } } - let(:message) { 'Jira settings saved, but not active.' } + let(:integration_params) { { active: false } } + let(:message) { 'Jira settings saved, but not active.' } - it_behaves_like 'service update' + it_behaves_like 'integration update' end - context 'wehn param `inherit_from_id` is set to empty string' do - let(:service_params) { { inherit_from_id: '' } } + context 'when param `inherit_from_id` is set to empty string' do + let(:integration_params) { { inherit_from_id: '' } } it 'sets inherit_from_id to nil' do - expect(service.reload.inherit_from_id).to eq(nil) + expect(integration.reload.inherit_from_id).to eq(nil) end end - context 'wehn param `inherit_from_id` is set to some value' do - let(:instance_service) { create(:jira_service, :instance) } - let(:service_params) { { inherit_from_id: instance_service.id } } + context 'when param `inherit_from_id` is set to some value' do + let(:instance_service) { create(:jira_integration, :instance) } + let(:integration_params) { { inherit_from_id: instance_service.id } } it 'sets inherit_from_id to value' do - expect(service.reload.inherit_from_id).to eq(instance_service.id) + expect(integration.reload.inherit_from_id).to eq(instance_service.id) end end end describe 'as JSON' do before do - stub_jira_service_test - put :update, params: project_params(service: service_params, format: :json) + stub_jira_integration_test + put :update, params: project_params(service: integration_params, format: :json) end context 'when update succeeds' do - let(:service_params) { { url: 'http://example.com' } } + let(:integration_params) { { url: 'http://example.com' } } it 'returns JSON response with no errors' do expect(response).to be_successful @@ -244,59 +248,67 @@ RSpec.describe Projects::ServicesController do end context 'when update fails' do - let(:service_params) { { url: '' } } + let(:integration_params) { { url: '' } } it 'returns JSON response with errors' do expect(response).to have_gitlab_http_status(:unprocessable_entity) expect(json_response).to include( 'active' => true, - 'errors' => { 'url' => ['must be a valid URL', %{can't be blank}] } + 'errors' => { 'url' => ['must be a valid URL', %(can't be blank)] } ) end end end - context 'Prometheus service' do - let!(:service) { create(:prometheus_service, project: project) } - let(:service_params) { { manual_configuration: '1', api_url: 'http://example.com' } } + context 'with Prometheus integration' do + let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) } - context 'feature flag :settings_operations_prometheus_service is enabled' do + let(:integration) { prometheus_integration } + let(:integration_params) { { manual_configuration: '1', api_url: 'http://example.com' } } + + context 'when feature flag :settings_operations_prometheus_service is enabled' do before do stub_feature_flags(settings_operations_prometheus_service: true) end it 'redirects user back to edit page with alert' do - put :update, params: project_params.merge(service: service_params) + put :update, params: project_params.merge(service: integration_params) - expect(response).to redirect_to(edit_project_service_path(project, service)) - expected_alert = "You can now manage your Prometheus settings on the <a href=\"#{project_settings_operations_path(project)}\">Operations</a> page. Fields on this page has been deprecated." + expect(response).to redirect_to(edit_project_service_path(project, integration)) + expected_alert = [ + "You can now manage your Prometheus settings on the", + %(<a href="#{project_settings_operations_path(project)}">Operations</a> page.), + "Fields on this page have been deprecated." + ].join(' ') expect(controller).to set_flash.now[:alert].to(expected_alert) end - it 'does not modify service' do - expect { put :update, params: project_params.merge(service: service_params) }.not_to change { project.prometheus_service.reload.attributes } + it 'does not modify integration' do + expect { put :update, params: project_params.merge(service: integration_params) } + .not_to change { project.prometheus_integration.reload.attributes } end end - context 'feature flag :settings_operations_prometheus_service is disabled' do + context 'when feature flag :settings_operations_prometheus_service is disabled' do before do stub_feature_flags(settings_operations_prometheus_service: false) end - it 'modifies service' do - expect { put :update, params: project_params.merge(service: service_params) }.to change { project.prometheus_service.reload.attributes } + it 'modifies integration' do + expect { put :update, params: project_params.merge(service: integration_params) } + .to change { project.prometheus_integration.reload.attributes } end end end end describe 'GET #edit' do - context 'Jira service' do - let(:service_param) { 'jira' } + context 'with Jira service' do + let(:integration_param) { 'jira' } before do - get :edit, params: project_params(id: service_param) + get :edit, params: project_params(id: integration_param) end context 'with approved services' do @@ -306,25 +318,30 @@ RSpec.describe Projects::ServicesController do end end - context 'Prometheus service' do - let(:service_param) { 'prometheus' } + context 'with Prometheus service' do + let(:integration_param) { 'prometheus' } - context 'feature flag :settings_operations_prometheus_service is enabled' do + context 'when feature flag :settings_operations_prometheus_service is enabled' do before do stub_feature_flags(settings_operations_prometheus_service: true) - get :edit, params: project_params(id: service_param) + get :edit, params: project_params(id: integration_param) end it 'renders deprecation warning notice' do - expected_alert = "You can now manage your Prometheus settings on the <a href=\"#{project_settings_operations_path(project)}\">Operations</a> page. Fields on this page has been deprecated." + expected_alert = [ + "You can now manage your Prometheus settings on the", + %(<a href="#{project_settings_operations_path(project)}">Operations</a> page.), + "Fields on this page have been deprecated." + ].join(' ') + expect(controller).to set_flash.now[:alert].to(expected_alert) end end - context 'feature flag :settings_operations_prometheus_service is disabled' do + context 'when feature flag :settings_operations_prometheus_service is disabled' do before do stub_feature_flags(settings_operations_prometheus_service: false) - get :edit, params: project_params(id: service_param) + get :edit, params: project_params(id: integration_param) end it 'does not render deprecation warning notice' do @@ -340,7 +357,7 @@ RSpec.describe Projects::ServicesController do opts.reverse_merge( namespace_id: project.namespace, project_id: project, - id: service.to_param + id: integration.to_param ) end end diff --git a/spec/controllers/projects/settings/access_tokens_controller_spec.rb b/spec/controllers/projects/settings/access_tokens_controller_spec.rb index 2a7e3d0b322..834a9e276f9 100644 --- a/spec/controllers/projects/settings/access_tokens_controller_spec.rb +++ b/spec/controllers/projects/settings/access_tokens_controller_spec.rb @@ -61,6 +61,14 @@ RSpec.describe Projects::Settings::AccessTokensController do expect { subject }.not_to change { User.count } end end + + context 'with custom access level' do + let(:access_token_params) { { name: 'Nerd bot', scopes: ["api"], expires_at: Date.today + 1.month, access_level: 20 } } + + subject { post :create, params: { namespace_id: project.namespace, project_id: project }.merge(project_access_token: access_token_params) } + + it_behaves_like 'project access tokens available #create' + end end describe '#revoke', :sidekiq_inline do diff --git a/spec/controllers/projects/tree_controller_spec.rb b/spec/controllers/projects/tree_controller_spec.rb index 8e4e275bdbe..143516e4712 100644 --- a/spec/controllers/projects/tree_controller_spec.rb +++ b/spec/controllers/projects/tree_controller_spec.rb @@ -3,8 +3,9 @@ require 'spec_helper' RSpec.describe Projects::TreeController do - let(:project) { create(:project, :repository) } - let(:user) { create(:user) } + let(:project) { create(:project, :repository, previous_default_branch: previous_default_branch) } + let(:previous_default_branch) { nil } + let(:user) { create(:user) } before do sign_in(user) @@ -55,6 +56,20 @@ RSpec.describe Projects::TreeController do it { is_expected.to respond_with(:not_found) } end + context "renamed default branch, valid file" do + let(:id) { 'old-default-branch/encoding/' } + let(:previous_default_branch) { 'old-default-branch' } + + it { is_expected.to redirect_to("/#{project.full_path}/-/tree/#{project.default_branch}/encoding/") } + end + + context "renamed default branch, invalid file" do + let(:id) { 'old-default-branch/invalid-path/' } + let(:previous_default_branch) { 'old-default-branch' } + + it { is_expected.to redirect_to("/#{project.full_path}/-/tree/#{project.default_branch}/invalid-path/") } + end + context "valid empty branch, invalid path" do let(:id) { 'empty-branch/invalid-path/' } |