diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-13 21:08:56 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-13 21:08:56 +0300 |
commit | 7b7bc31c5ba07eebe62e2f2582f111ce24285cd4 (patch) | |
tree | 70c795a932a603e49176d30ee5f0835fcfed46c2 /spec/requests | |
parent | cb38c5062c623059d311c4e9e37428eacdea95d6 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/files_spec.rb | 6 | ||||
-rw-r--r-- | spec/requests/api/internal/pages_spec.rb | 99 | ||||
-rw-r--r-- | spec/requests/projects/merge_requests_discussions_spec.rb | 261 |
3 files changed, 225 insertions, 141 deletions
diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb index f68ea0cd84c..c9341934ec9 100644 --- a/spec/requests/api/files_spec.rb +++ b/spec/requests/api/files_spec.rb @@ -141,7 +141,11 @@ RSpec.describe API::Files, feature_category: :source_code_management do it 'caches sha256 of the content', :use_clean_rails_redis_caching do head api(route(file_path), current_user, **options), params: params - expect(Gitlab::Cache::Client).to receive(:build_with_metadata).and_call_original + expect(Gitlab::Cache::Client).to receive(:build_with_metadata).with( + cache_identifier: 'API::Files#content_sha', + feature_category: :source_code_management, + backing_resource: :gitaly + ).and_call_original expect(Rails.cache.fetch("blob_content_sha256:#{project.full_path}:#{response.headers['X-Gitlab-Blob-Id']}")) .to eq(content_sha256) diff --git a/spec/requests/api/internal/pages_spec.rb b/spec/requests/api/internal/pages_spec.rb index 56f1089843b..67f5b7f8ccb 100644 --- a/spec/requests/api/internal/pages_spec.rb +++ b/spec/requests/api/internal/pages_spec.rb @@ -212,7 +212,98 @@ RSpec.describe API::Internal::Pages, feature_category: :pages do 'sha256' => deployment.file_sha256, 'file_size' => deployment.size, 'file_count' => deployment.file_count - } + }, + 'unique_domain' => nil + } + ] + ) + end + end + end + + context 'unique domain' do + let(:project) { create(:project) } + + before do + project.project_setting.update!( + pages_unique_domain: 'unique-domain', + pages_unique_domain_enabled: true) + end + + context 'when there are no pages deployed for the related project' do + it 'responds with 204 No Content' do + query_host('unique-domain.example.com') + + expect(response).to have_gitlab_http_status(:no_content) + end + end + + context 'when there are pages deployed for the related project' do + context 'when the feature flag is disabled' do + before do + stub_feature_flags(pages_unique_domain: false) + end + + context 'when there are no pages deployed for the related project' do + it 'responds with 204 No Content' do + deploy_pages(project) + + query_host('unique-domain.example.com') + + expect(response).to have_gitlab_http_status(:no_content) + end + end + end + + context 'when the unique domain is disabled' do + before do + project.project_setting.update!(pages_unique_domain_enabled: false) + end + + context 'when there are no pages deployed for the related project' do + it 'responds with 204 No Content' do + deploy_pages(project) + + query_host('unique-domain.example.com') + + expect(response).to have_gitlab_http_status(:no_content) + end + end + end + + it 'domain lookup is case insensitive' do + deploy_pages(project) + + query_host('Unique-Domain.example.com') + + expect(response).to have_gitlab_http_status(:ok) + end + + it 'responds with the correct domain configuration' do + deploy_pages(project) + + query_host('unique-domain.example.com') + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('internal/pages/virtual_domain') + + deployment = project.pages_metadatum.pages_deployment + expect(json_response['lookup_paths']).to eq( + [ + { + 'project_id' => project.id, + 'access_control' => false, + 'https_only' => false, + 'prefix' => '/', + 'source' => { + 'type' => 'zip', + 'path' => deployment.file.url(expire_at: 1.day.from_now), + 'global_id' => "gid://gitlab/PagesDeployment/#{deployment.id}", + 'sha256' => deployment.file_sha256, + 'file_size' => deployment.size, + 'file_count' => deployment.file_count + }, + 'unique_domain' => 'unique-domain' } ] ) @@ -253,7 +344,8 @@ RSpec.describe API::Internal::Pages, feature_category: :pages do 'sha256' => deployment.file_sha256, 'file_size' => deployment.size, 'file_count' => deployment.file_count - } + }, + 'unique_domain' => nil } ] ) @@ -299,7 +391,8 @@ RSpec.describe API::Internal::Pages, feature_category: :pages do 'sha256' => deployment.file_sha256, 'file_size' => deployment.size, 'file_count' => deployment.file_count - } + }, + 'unique_domain' => nil } ] ) diff --git a/spec/requests/projects/merge_requests_discussions_spec.rb b/spec/requests/projects/merge_requests_discussions_spec.rb index d82fa284a42..54ee5e489f7 100644 --- a/spec/requests/projects/merge_requests_discussions_spec.rb +++ b/spec/requests/projects/merge_requests_discussions_spec.rb @@ -59,7 +59,7 @@ RSpec.describe 'merge requests discussions', feature_category: :source_code_mana .to change { Gitlab::GitalyClient.get_request_count }.by_at_most(4) end - context 'caching', :use_clean_rails_memory_store_caching do + context 'caching' do let(:reference) { create(:issue, project: project) } let(:author) { create(:user) } let!(:first_note) { create(:diff_note_on_merge_request, author: author, noteable: merge_request, project: project, note: "reference: #{reference.to_reference}") } @@ -81,193 +81,180 @@ RSpec.describe 'merge requests discussions', feature_category: :source_code_mana shared_examples 'cache hit' do it 'gets cached on subsequent requests' do - expect_next_instance_of(DiscussionSerializer) do |serializer| - expect(serializer).not_to receive(:represent) - end + expect(DiscussionSerializer).not_to receive(:new) send_request end end - context 'when mr_discussions_http_cache and disabled_mr_discussions_redis_cache are enabled' do - before do - send_request - end - - it_behaves_like 'cache hit' + before do + send_request + end - context 'when a note in a discussion got updated' do - before do - first_note.update!(updated_at: 1.minute.from_now) - end + it_behaves_like 'cache hit' - it_behaves_like 'cache miss' do - let(:changed_notes) { [first_note, second_note] } - end + context 'when a note in a discussion got updated' do + before do + first_note.update!(updated_at: 1.minute.from_now) end - context 'when a note in a discussion got its reference state updated' do - before do - reference.close! - end + it_behaves_like 'cache miss' do + let(:changed_notes) { [first_note, second_note] } + end + end - it_behaves_like 'cache miss' do - let(:changed_notes) { [first_note, second_note] } - end + context 'when a note in a discussion got its reference state updated' do + before do + reference.close! end - context 'when a note in a discussion got resolved' do - before do - travel_to(1.minute.from_now) do - first_note.resolve!(user) - end - end + it_behaves_like 'cache miss' do + let(:changed_notes) { [first_note, second_note] } + end + end - it_behaves_like 'cache miss' do - let(:changed_notes) { [first_note, second_note] } + context 'when a note in a discussion got resolved' do + before do + travel_to(1.minute.from_now) do + first_note.resolve!(user) end end - context 'when a note is added to a discussion' do - let!(:third_note) { create(:diff_note_on_merge_request, in_reply_to: first_note, noteable: merge_request, project: project) } - - it_behaves_like 'cache miss' do - let(:changed_notes) { [first_note, second_note, third_note] } - end + it_behaves_like 'cache miss' do + let(:changed_notes) { [first_note, second_note] } end + end - context 'when a note is removed from a discussion' do - before do - second_note.destroy! - end + context 'when a note is added to a discussion' do + let!(:third_note) { create(:diff_note_on_merge_request, in_reply_to: first_note, noteable: merge_request, project: project) } - it_behaves_like 'cache miss' do - let(:changed_notes) { [first_note] } - end + it_behaves_like 'cache miss' do + let(:changed_notes) { [first_note, second_note, third_note] } end + end - context 'when an emoji is awarded to a note in discussion' do - before do - travel_to(1.minute.from_now) do - create(:award_emoji, awardable: first_note) - end - end + context 'when a note is removed from a discussion' do + before do + second_note.destroy! + end - it_behaves_like 'cache miss' do - let(:changed_notes) { [first_note, second_note] } - end + it_behaves_like 'cache miss' do + let(:changed_notes) { [first_note] } end + end - context 'when an award emoji is removed from a note in discussion' do - before do - travel_to(1.minute.from_now) do - award_emoji.destroy! - end + context 'when an emoji is awarded to a note in discussion' do + before do + travel_to(1.minute.from_now) do + create(:award_emoji, awardable: first_note) end + end - it_behaves_like 'cache miss' do - let(:changed_notes) { [first_note, second_note] } - end + it_behaves_like 'cache miss' do + let(:changed_notes) { [first_note, second_note] } end + end - context 'when the diff note position changes' do - before do - # This replicates a position change wherein timestamps aren't updated - # which is why `Gitlab::Timeless.timeless` is utilized. This is the - # same approach being used in Discussions::UpdateDiffPositionService - # which is responsible for updating the positions of diff discussions - # when MR updates. - first_note.position = Gitlab::Diff::Position.new( - old_path: first_note.position.old_path, - new_path: first_note.position.new_path, - old_line: first_note.position.old_line, - new_line: first_note.position.new_line + 1, - diff_refs: first_note.position.diff_refs - ) - - Gitlab::Timeless.timeless(first_note, &:save) + context 'when an award emoji is removed from a note in discussion' do + before do + travel_to(1.minute.from_now) do + award_emoji.destroy! end + end - it_behaves_like 'cache miss' do - let(:changed_notes) { [first_note, second_note] } - end + it_behaves_like 'cache miss' do + let(:changed_notes) { [first_note, second_note] } end + end - context 'when the HEAD diff note position changes' do - before do - # This replicates a DiffNotePosition change. This is the same approach - # being used in Discussions::CaptureDiffNotePositionService which is - # responsible for updating/creating DiffNotePosition of a diff discussions - # in relation to HEAD diff. - new_position = Gitlab::Diff::Position.new( - old_path: first_note.position.old_path, - new_path: first_note.position.new_path, - old_line: first_note.position.old_line, - new_line: first_note.position.new_line + 1, - diff_refs: first_note.position.diff_refs - ) - - DiffNotePosition.create_or_update_for( - first_note, - diff_type: :head, - position: new_position, - line_code: 'bd4b7bfff3a247ccf6e3371c41ec018a55230bcc_534_521' - ) - end + context 'when the diff note position changes' do + before do + # This replicates a position change wherein timestamps aren't updated + # which is why `Gitlab::Timeless.timeless` is utilized. This is the + # same approach being used in Discussions::UpdateDiffPositionService + # which is responsible for updating the positions of diff discussions + # when MR updates. + first_note.position = Gitlab::Diff::Position.new( + old_path: first_note.position.old_path, + new_path: first_note.position.new_path, + old_line: first_note.position.old_line, + new_line: first_note.position.new_line + 1, + diff_refs: first_note.position.diff_refs + ) + + Gitlab::Timeless.timeless(first_note, &:save) + end - it_behaves_like 'cache miss' do - let(:changed_notes) { [first_note, second_note] } - end + it_behaves_like 'cache miss' do + let(:changed_notes) { [first_note, second_note] } end + end - context 'when author detail changes' do - before do - author.update!(name: "#{author.name} (Updated)") - end + context 'when the HEAD diff note position changes' do + before do + # This replicates a DiffNotePosition change. This is the same approach + # being used in Discussions::CaptureDiffNotePositionService which is + # responsible for updating/creating DiffNotePosition of a diff discussions + # in relation to HEAD diff. + new_position = Gitlab::Diff::Position.new( + old_path: first_note.position.old_path, + new_path: first_note.position.new_path, + old_line: first_note.position.old_line, + new_line: first_note.position.new_line + 1, + diff_refs: first_note.position.diff_refs + ) + + DiffNotePosition.create_or_update_for( + first_note, + diff_type: :head, + position: new_position, + line_code: 'bd4b7bfff3a247ccf6e3371c41ec018a55230bcc_534_521' + ) + end - it_behaves_like 'cache miss' do - let(:changed_notes) { [first_note, second_note] } - end + it_behaves_like 'cache miss' do + let(:changed_notes) { [first_note, second_note] } end + end - context 'when author status changes' do - before do - Users::SetStatusService.new(author, message: "updated status").execute - end + context 'when author detail changes' do + before do + author.update!(name: "#{author.name} (Updated)") + end - it_behaves_like 'cache miss' do - let(:changed_notes) { [first_note, second_note] } - end + it_behaves_like 'cache miss' do + let(:changed_notes) { [first_note, second_note] } end + end - context 'when author role changes' do - before do - Members::UpdateService.new(owner, access_level: Gitlab::Access::GUEST).execute(author_membership) - end + context 'when author status changes' do + before do + Users::SetStatusService.new(author, message: "updated status").execute + end - it_behaves_like 'cache miss' do - let(:changed_notes) { [first_note, second_note] } - end + it_behaves_like 'cache miss' do + let(:changed_notes) { [first_note, second_note] } end + end - context 'when current_user role changes' do - before do - Members::UpdateService.new(owner, access_level: Gitlab::Access::GUEST).execute(project.member(user)) - end + context 'when author role changes' do + before do + Members::UpdateService.new(owner, access_level: Gitlab::Access::GUEST).execute(author_membership) + end - it_behaves_like 'cache miss' do - let(:changed_notes) { [first_note, second_note] } - end + it_behaves_like 'cache miss' do + let(:changed_notes) { [first_note, second_note] } end end - context 'when disabled_mr_discussions_redis_cache is disabled' do + context 'when current_user role changes' do before do - stub_feature_flags(disabled_mr_discussions_redis_cache: false) - send_request + Members::UpdateService.new(owner, access_level: Gitlab::Access::GUEST).execute(project.member(user)) end - it_behaves_like 'cache hit' + it_behaves_like 'cache miss' do + let(:changed_notes) { [first_note, second_note] } + end end end end |