diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-05 00:07:14 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-05 00:07:14 +0000 |
commit | 86af4d6a04a1c30ebfe2377cdc3270ade911b2fe (patch) | |
tree | 37df9fde7aee7b97d088afe2073c67b9114af53f /spec | |
parent | 2242221252d13fdf322b5e59f971a689831c541b (diff) | |
download | gitlab-ce-86af4d6a04a1c30ebfe2377cdc3270ade911b2fe.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/dashboard/issuables_counter_spec.rb | 27 | ||||
-rw-r--r-- | spec/features/projects/jobs_spec.rb | 14 | ||||
-rw-r--r-- | spec/helpers/issuables_helper_spec.rb | 28 | ||||
-rw-r--r-- | spec/lib/api/helpers_spec.rb | 19 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/status/build/manual_spec.rb | 31 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 47 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 22 | ||||
-rw-r--r-- | spec/requests/api/files_spec.rb | 120 |
8 files changed, 199 insertions, 109 deletions
diff --git a/spec/features/dashboard/issuables_counter_spec.rb b/spec/features/dashboard/issuables_counter_spec.rb index 5c7285f0491..5dc59cfa841 100644 --- a/spec/features/dashboard/issuables_counter_spec.rb +++ b/spec/features/dashboard/issuables_counter_spec.rb @@ -12,7 +12,6 @@ RSpec.describe 'Navigation bar counter', :use_clean_rails_memory_store_caching, issue.assignees = [user] merge_request.update!(assignees: [user]) sign_in(user) - stub_feature_flags(limit_assigned_issues_count: false) end it 'reflects dashboard issues count' do @@ -20,9 +19,9 @@ RSpec.describe 'Navigation bar counter', :use_clean_rails_memory_store_caching, expect_counters('issues', '1', n_("%d assigned issue", "%d assigned issues", 1) % 1) - issue.assignees = [] + issue.update!(assignees: []) - user.invalidate_cache_counts + Users::AssignedIssuesCountService.new(current_user: user).delete_cache travel_to(3.minutes.from_now) do visit issues_path @@ -31,28 +30,6 @@ RSpec.describe 'Navigation bar counter', :use_clean_rails_memory_store_caching, end end - context 'when :limit_assigned_issues_count FF is used' do - before do - stub_feature_flags(limit_assigned_issues_count: true) - end - - it 'reflects dashboard issues count' do - visit issues_path - - expect_counters('issues', '1', n_("%d assigned issue", "%d assigned issues", 1) % 1) - - issue.update!(assignees: []) - - Users::AssignedIssuesCountService.new(current_user: user).delete_cache - - travel_to(3.minutes.from_now) do - visit issues_path - - expect_counters('issues', '0', n_("%d assigned issue", "%d assigned issues", 0) % 0) - end - end - end - it 'reflects dashboard merge requests count', :js do visit merge_requests_path diff --git a/spec/features/projects/jobs_spec.rb b/spec/features/projects/jobs_spec.rb index 557a20ff2d6..4734a607ef1 100644 --- a/spec/features/projects/jobs_spec.rb +++ b/spec/features/projects/jobs_spec.rb @@ -739,7 +739,12 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state, feature_category: :proj it 'shows manual action empty state', :js do expect(page).to have_content(job.detailed_status(user).illustration[:title]) expect(page).to have_content('This job requires a manual action') - expect(page).to have_content('This job requires manual intervention to start. Before starting this job, you can add variables below for last-minute configuration changes.') + expect(page).to have_content( + _( + 'This job does not start automatically and must be started manually. ' \ + 'You can add CI/CD variables below for last-minute configuration changes before starting the job.' + ) + ) expect(page).to have_button('Trigger this manual action') end @@ -772,7 +777,12 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state, feature_category: :proj wait_for_requests expect(page).to have_content('This job requires a manual action') - expect(page).to have_content('This job requires manual intervention to start. Before starting this job, you can add variables below for last-minute configuration changes.') + expect(page).to have_content( + _( + 'This job does not start automatically and must be started manually. ' \ + 'You can add CI/CD variables below for last-minute configuration changes before starting the job.' + ) + ) expect(page).to have_button('Trigger this manual action') end end diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb index 15b57a4c9eb..2fb7c07cd36 100644 --- a/spec/helpers/issuables_helper_spec.rb +++ b/spec/helpers/issuables_helper_spec.rb @@ -112,19 +112,7 @@ RSpec.describe IssuablesHelper do context 'when assigned issues count is over 100' do let_it_be(:issues) { create_list(:issue, 101, project: project, assignees: [user]) } - before do - stub_feature_flags(limit_assigned_issues_count: false) - end - - it { is_expected.to eq 101 } - - context 'when FF limit_assigned_issues_count is enabled' do - before do - stub_feature_flags(limit_assigned_issues_count: true) - end - - it { is_expected.to eq 100 } - end + it { is_expected.to eq 100 } end end end @@ -142,19 +130,7 @@ RSpec.describe IssuablesHelper do context 'when assigned issues count is over 99' do let_it_be(:issues) { create_list(:issue, 100, project: project, assignees: [user]) } - before do - stub_feature_flags(limit_assigned_issues_count: false) - end - - it { is_expected.to eq '100' } - - context 'when FF limit_assigned_issues_count is enabled' do - before do - stub_feature_flags(limit_assigned_issues_count: true) - end - - it { is_expected.to eq '99+' } - end + it { is_expected.to eq '99+' } end end diff --git a/spec/lib/api/helpers_spec.rb b/spec/lib/api/helpers_spec.rb index d24a3bd13c0..a0f5ee1ea95 100644 --- a/spec/lib/api/helpers_spec.rb +++ b/spec/lib/api/helpers_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe API::Helpers do +RSpec.describe API::Helpers, feature_category: :not_owned do using RSpec::Parameterized::TableSyntax subject(:helper) { Class.new.include(described_class).new } @@ -11,7 +11,7 @@ RSpec.describe API::Helpers do include Rack::Test::Methods let(:user) { build(:user, id: 42) } - + let(:request) { instance_double(Rack::Request) } let(:helper) do Class.new(Grape::API::Instance) do helpers API::APIGuard::HelperMethods @@ -797,12 +797,13 @@ RSpec.describe API::Helpers do describe '#present_artifacts_file!' do context 'with object storage' do let(:artifact) { create(:ci_job_artifact, :zip, :remote_store) } + let(:is_head_request) { false } subject { helper.present_artifacts_file!(artifact.file) } before do allow(helper).to receive(:env).and_return({}) - + allow(helper).to receive(:request).and_return(instance_double(Rack::Request, head?: is_head_request)) stub_artifacts_object_storage(enabled: true) end @@ -814,6 +815,18 @@ RSpec.describe API::Helpers do subject end + + context 'requested with HEAD' do + let(:is_head_request) { true } + + it 'redirects to a CDN-fronted URL' do + expect(helper).to receive(:redirect) + expect(helper).to receive(:signed_head_url).and_call_original + expect(Gitlab::ApplicationContext).to receive(:push).with(artifact: artifact.file.model).and_call_original + + subject + end + end end end diff --git a/spec/lib/gitlab/ci/status/build/manual_spec.rb b/spec/lib/gitlab/ci/status/build/manual_spec.rb index 0a4cc6b405a..8f5d1558314 100644 --- a/spec/lib/gitlab/ci/status/build/manual_spec.rb +++ b/spec/lib/gitlab/ci/status/build/manual_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::Status::Build::Manual do +RSpec.describe Gitlab::Ci::Status::Build::Manual, feature_category: :continuous_integration do let_it_be(:user) { create(:user) } let_it_be(:job) { create(:ci_build, :manual) } @@ -18,7 +18,28 @@ RSpec.describe Gitlab::Ci::Status::Build::Manual do job.project.add_maintainer(user) end - it { expect(subject.illustration[:content]).to match /This job requires manual intervention to start/ } + context 'when the job has not been played' do + it 'instructs the user about possible actions' do + expect(subject.illustration[:content]).to eq( + _( + 'This job does not start automatically and must be started manually. ' \ + 'You can add CI/CD variables below for last-minute configuration changes before starting the job.' + ) + ) + end + end + + context 'when the job is retryable' do + before do + job.update!(status: :failed) + end + + it 'instructs the user about possible actions' do + expect(subject.illustration[:content]).to eq( + _("You can modify this job's CI/CD variables before running it again.") + ) + end + end end context 'when the user can not trigger the job because of outdated deployment' do @@ -30,7 +51,11 @@ RSpec.describe Gitlab::Ci::Status::Build::Manual do end context 'when the user can not trigger the job due to another reason' do - it { expect(subject.illustration[:content]).to match /This job does not run automatically and must be started manually/ } + it 'informs the user' do + expect(subject.illustration[:content]).to eq( + _("This job does not run automatically and must be started manually, but you do not have access to it.") + ) + end end end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 969a279dd52..ab44f656a66 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -534,21 +534,48 @@ RSpec.describe Repository do end describe '#find_commits_by_message' do - it 'returns commits with messages containing a given string' do - commit_ids = repository.find_commits_by_message('submodule').map(&:id) + subject(:find_commits_by_message) { repository.find_commits_by_message(query) } - expect(commit_ids).to include( - '5937ac0a7beb003549fc5fd26fc247adbce4a52e', - '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9', - 'cfe32cf61b73a0d5e9f13e774abde7ff789b1660' - ) + let(:commit_ids) { find_commits_by_message.map(&:id) } + let(:query) { 'submodule' } + let(:expected_commit_ids) do + %w[ + 5937ac0a7beb003549fc5fd26fc247adbce4a52e + 6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9 + cfe32cf61b73a0d5e9f13e774abde7ff789b1660 + ] + end + + it 'returns commits with messages containing a given string' do + expect(commit_ids).to include(*expected_commit_ids) expect(commit_ids).not_to include('913c66a37b4a45b9769037c55c2d238bd0942d2e') end - it 'is case insensitive' do - commit_ids = repository.find_commits_by_message('SUBMODULE').map(&:id) + context 'when query is in UPCASE' do + let(:query) { 'SUBMODULE' } + + it 'is case insensitive' do + expect(commit_ids).to include(*expected_commit_ids) + end + end + + context 'when message has surrounding spaces' do + let(:query) { ' submodule ' } - expect(commit_ids).to include('5937ac0a7beb003549fc5fd26fc247adbce4a52e') + it 'removes spaces and returns commits by message' do + expect(commit_ids).to include(*expected_commit_ids) + expect(commit_ids).not_to include('913c66a37b4a45b9769037c55c2d238bd0942d2e') + end + + context 'when feature flag "commit_search_trailing_spaces" is disabled' do + before do + stub_feature_flags(commit_search_trailing_spaces: false) + end + + it 'returns an empty list' do + expect(commit_ids).to be_empty + end + end end describe 'when storage is broken', :broken_storage do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 5b6f15176be..3be7240fa16 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -5259,36 +5259,16 @@ RSpec.describe User do describe '#invalidate_issue_cache_counts' do let(:user) { build_stubbed(:user) } - before do - stub_feature_flags(limit_assigned_issues_count: false) - end - it 'invalidates cache for issue counter' do cache_mock = double expect(cache_mock).to receive(:delete).with(['users', user.id, 'assigned_open_issues_count']) + expect(cache_mock).to receive(:delete).with(['users', user.id, 'max_assigned_open_issues_count']) allow(Rails).to receive(:cache).and_return(cache_mock) user.invalidate_issue_cache_counts end - - context 'when limit_assigned_issues_count is enabled' do - before do - stub_feature_flags(limit_assigned_issues_count: true) - end - - it 'invalidates cache for issue counter' do - cache_mock = double - - expect(cache_mock).to receive(:delete).with(['users', user.id, 'assigned_open_issues_count']) - expect(cache_mock).to receive(:delete).with(['users', user.id, 'max_assigned_open_issues_count']) - - allow(Rails).to receive(:cache).and_return(cache_mock) - - user.invalidate_issue_cache_counts - end - end end describe '#invalidate_merge_request_cache_counts' do diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb index 9cee3c06bb1..f4066c54c47 100644 --- a/spec/requests/api/files_spec.rb +++ b/spec/requests/api/files_spec.rb @@ -6,6 +6,24 @@ RSpec.describe API::Files, feature_category: :source_code_management do include RepoHelpers let_it_be(:group) { create(:group, :public) } + let(:helper) do + fake_class = Class.new do + include ::API::Helpers::HeadersHelpers + + attr_reader :headers + + def initialize + @headers = {} + end + + def header(key, value) + @headers[key] = value + end + end + + fake_class.new + end + let_it_be_with_refind(:user) { create(:user) } let_it_be(:inherited_guest) { create(:user) } let_it_be(:inherited_reporter) { create(:user) } @@ -37,25 +55,9 @@ RSpec.describe API::Files, feature_category: :source_code_management do } end - let(:author_email) { 'user@example.org' } - let(:author_name) { 'John Doe' } - - let(:helper) do - fake_class = Class.new do - include ::API::Helpers::HeadersHelpers - - attr_reader :headers - - def initialize - @headers = {} - end - - def header(key, value) - @headers[key] = value - end - end - - fake_class.new + shared_context 'with author parameters' do + let(:author_email) { 'user@example.org' } + let(:author_name) { 'John Doe' } end before_all do @@ -702,6 +704,80 @@ RSpec.describe API::Files, feature_category: :source_code_management do end end + describe 'HEAD /projects/:id/repository/files/:file_path/raw' do + let(:request) { head api(route(file_path) + '/raw', current_user), params: params } + + describe 'response headers' do + subject { response.headers } + + context 'and user is a developer' do + let(:current_user) { user } + + it 'responds with blob data' do + request + headers = response.headers + expect(headers['X-Gitlab-File-Name']).to eq(file_name) + expect(headers['X-Gitlab-File-Path']).to eq('files/ruby/popen.rb') + expect(headers['X-Gitlab-Content-Sha256']).to eq('c440cd09bae50c4632cc58638ad33c6aa375b6109d811e76a9cc3a613c1e8887') + expect(headers['X-Gitlab-Ref']).to eq('master') + expect(headers['X-Gitlab-Blob-Id']).to eq('7e3e39ebb9b2bf433b4ad17313770fbe4051649c') + expect(headers['X-Gitlab-Commit-Id']).to eq(project.repository.commit.id) + expect(headers['X-Gitlab-Last-Commit-Id']).to eq('570e7b2abdd848b95f2f578043fc23bd6f6fd24d') + end + + context 'when lfs parameter is true and the project has lfs enabled' do + before do + allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) + project.update_attribute(:lfs_enabled, true) + end + + let(:request) { head api(route('files%2Flfs%2Flfs_object.iso') + '/raw', current_user), params: params.merge(lfs: true) } + + context 'and the file has an lfs object' do + let_it_be(:lfs_object) { create(:lfs_object, :with_file, oid: '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897') } + + it 'responds with 404' do + request + + expect(response).to have_gitlab_http_status(:not_found) + end + + context 'and the project has access to the lfs object' do + before do + project.lfs_objects << lfs_object + end + + context 'and lfs uses AWS' do + before do + stub_lfs_object_storage(config: Gitlab.config.lfs.object_store.merge(connection: { + provider: 'AWS', + aws_access_key_id: '', + aws_secret_access_key: '' + })) + lfs_object.file.migrate!(LfsObjectUploader::Store::REMOTE) + end + + it 'redirects to the lfs object file with a signed url' do + request + + expect(response).to have_gitlab_http_status(:found) + expect(response.location).to include(lfs_object.reload.file.path) + expect(response.location).to include('X-Amz-SignedHeaders') + end + end + end + end + end + end + + context 'and user is a guest' do + it_behaves_like '403 response' do + let(:request) { head api(route(file_path), guest), params: params } + end + end + end + end + describe 'GET /projects/:id/repository/files/:file_path/raw' do shared_examples_for 'repository raw files' do it 'returns 400 when file path is invalid' do @@ -1006,6 +1082,8 @@ RSpec.describe API::Files, feature_category: :source_code_management do end context 'when specifying an author' do + include_context 'with author parameters' + it 'creates a new file with the specified author' do params.merge!(author_email: author_email, author_name: author_name) post api(route('new_file_with_author%2Etxt'), user), params: params @@ -1163,6 +1241,8 @@ RSpec.describe API::Files, feature_category: :source_code_management do end context 'when specifying an author' do + include_context 'with author parameters' + it 'updates a file with the specified author' do params.merge!(author_email: author_email, author_name: author_name, content: 'New content') @@ -1236,6 +1316,8 @@ RSpec.describe API::Files, feature_category: :source_code_management do end context 'when specifying an author' do + include_context 'with author parameters' + before do params.merge!(author_email: author_email, author_name: author_name) end |