diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/requests/api/tags_spec.rb | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/requests/api/tags_spec.rb')
-rw-r--r-- | spec/requests/api/tags_spec.rb | 230 |
1 files changed, 148 insertions, 82 deletions
diff --git a/spec/requests/api/tags_spec.rb b/spec/requests/api/tags_spec.rb index b029c0f5793..3c698cf577e 100644 --- a/spec/requests/api/tags_spec.rb +++ b/spec/requests/api/tags_spec.rb @@ -17,131 +17,197 @@ RSpec.describe API::Tags do end describe 'GET /projects/:id/repository/tags' do - let(:route) { "/projects/#{project_id}/repository/tags" } + shared_examples "get repository tags" do + let(:route) { "/projects/#{project_id}/repository/tags" } - context 'sorting' do - let(:current_user) { user } + context 'sorting' do + let(:current_user) { user } - it 'sorts by descending order by default' do - get api(route, current_user) + it 'sorts by descending order by default' do + get api(route, current_user) - desc_order_tags = project.repository.tags.sort_by { |tag| tag.dereferenced_target.committed_date } - desc_order_tags.reverse!.map! { |tag| tag.dereferenced_target.id } + desc_order_tags = project.repository.tags.sort_by { |tag| tag.dereferenced_target.committed_date } + desc_order_tags.reverse!.map! { |tag| tag.dereferenced_target.id } - expect(json_response.map { |tag| tag['commit']['id'] }).to eq(desc_order_tags) - end + expect(json_response.map { |tag| tag['commit']['id'] }).to eq(desc_order_tags) + end - it 'sorts by ascending order if specified' do - get api("#{route}?sort=asc", current_user) + it 'sorts by ascending order if specified' do + get api("#{route}?sort=asc", current_user) - asc_order_tags = project.repository.tags.sort_by { |tag| tag.dereferenced_target.committed_date } - asc_order_tags.map! { |tag| tag.dereferenced_target.id } + asc_order_tags = project.repository.tags.sort_by { |tag| tag.dereferenced_target.committed_date } + asc_order_tags.map! { |tag| tag.dereferenced_target.id } - expect(json_response.map { |tag| tag['commit']['id'] }).to eq(asc_order_tags) - end + expect(json_response.map { |tag| tag['commit']['id'] }).to eq(asc_order_tags) + end - it 'sorts by name in descending order when requested' do - get api("#{route}?order_by=name", current_user) + it 'sorts by name in descending order when requested' do + get api("#{route}?order_by=name", current_user) - ordered_by_name = project.repository.tags.map { |tag| tag.name }.sort.reverse + ordered_by_name = project.repository.tags.map { |tag| tag.name }.sort.reverse - expect(json_response.map { |tag| tag['name'] }).to eq(ordered_by_name) - end + expect(json_response.map { |tag| tag['name'] }).to eq(ordered_by_name) + end - it 'sorts by name in ascending order when requested' do - get api("#{route}?order_by=name&sort=asc", current_user) + it 'sorts by name in ascending order when requested' do + get api("#{route}?order_by=name&sort=asc", current_user) - ordered_by_name = project.repository.tags.map { |tag| tag.name }.sort + ordered_by_name = project.repository.tags.map { |tag| tag.name }.sort - expect(json_response.map { |tag| tag['name'] }).to eq(ordered_by_name) + expect(json_response.map { |tag| tag['name'] }).to eq(ordered_by_name) + end end - end - context 'searching' do - it 'only returns searched tags' do - get api("#{route}", user), params: { search: 'v1.1.0' } + context 'searching' do + it 'only returns searched tags' do + get api("#{route}", user), params: { search: 'v1.1.0' } - expect(response).to have_gitlab_http_status(:ok) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.size).to eq(1) - expect(json_response[0]['name']).to eq('v1.1.0') + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.size).to eq(1) + expect(json_response[0]['name']).to eq('v1.1.0') + end end - end - shared_examples_for 'repository tags' do - it 'returns the repository tags' do - get api(route, current_user) + shared_examples_for 'repository tags' do + it 'returns the repository tags' do + get api(route, current_user) - expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('public_api/v4/tags') - expect(response).to include_pagination_headers - expect(json_response.map { |r| r['name'] }).to include(tag_name) + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('public_api/v4/tags') + expect(response).to include_pagination_headers + expect(json_response.map { |r| r['name'] }).to include(tag_name) + end + + context 'when repository is disabled' do + include_context 'disabled repository' + + it_behaves_like '403 response' do + let(:request) { get api(route, current_user) } + end + end end - context 'when repository is disabled' do - include_context 'disabled repository' + context 'when unauthenticated', 'and project is public' do + let(:project) { create(:project, :public, :repository) } - it_behaves_like '403 response' do - let(:request) { get api(route, current_user) } + it_behaves_like 'repository tags' + end + + context 'when unauthenticated', 'and project is private' do + it_behaves_like '404 response' do + let(:request) { get api(route) } + let(:message) { '404 Project Not Found' } end end - end - context 'when unauthenticated', 'and project is public' do - let(:project) { create(:project, :public, :repository) } + context 'when authenticated', 'as a maintainer' do + let(:current_user) { user } - it_behaves_like 'repository tags' - end + it_behaves_like 'repository tags' - context 'when unauthenticated', 'and project is private' do - it_behaves_like '404 response' do - let(:request) { get api(route) } - let(:message) { '404 Project Not Found' } + context 'requesting with the escaped project full path' do + let(:project_id) { CGI.escape(project.full_path) } + + it_behaves_like 'repository tags' + end end - end - context 'when authenticated', 'as a maintainer' do - let(:current_user) { user } + context 'when authenticated', 'as a guest' do + it_behaves_like '403 response' do + let(:request) { get api(route, guest) } + end + end - it_behaves_like 'repository tags' + context 'with releases' do + let(:description) { 'Awesome release!' } - context 'requesting with the escaped project full path' do - let(:project_id) { CGI.escape(project.full_path) } + let!(:release) do + create(:release, + :legacy, + project: project, + tag: tag_name, + description: description) + end - it_behaves_like 'repository tags' + it 'returns an array of project tags with release info' do + get api(route, user) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('public_api/v4/tags') + expect(response).to include_pagination_headers + + expected_tag = json_response.find { |r| r['name'] == tag_name } + expect(expected_tag['message']).to eq(tag_message) + expect(expected_tag['release']['description']).to eq(description) + end end end - context 'when authenticated', 'as a guest' do - it_behaves_like '403 response' do - let(:request) { get api(route, guest) } + context ":api_caching_tags flag enabled", :use_clean_rails_memory_store_caching do + before do + stub_feature_flags(api_caching_tags: true) end - end - context 'with releases' do - let(:description) { 'Awesome release!' } + it_behaves_like "get repository tags" - let!(:release) do - create(:release, - :legacy, - project: project, - tag: tag_name, - description: description) - end + describe "cache expiry" do + let(:route) { "/projects/#{project_id}/repository/tags" } + let(:current_user) { user } - it 'returns an array of project tags with release info' do - get api(route, user) + before do + # Set the cache + get api(route, current_user) + end - expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('public_api/v4/tags') - expect(response).to include_pagination_headers + it "is cached" do + expect(API::Entities::Tag).not_to receive(:represent) + + get api(route, current_user) + end + + shared_examples "cache expired" do + it "isn't cached" do + expect(API::Entities::Tag).to receive(:represent).exactly(3).times + + get api(route, current_user) + end + end + + context "when protected tag is changed" do + before do + create(:protected_tag, name: tag_name, project: project) + end + + it_behaves_like "cache expired" + end - expected_tag = json_response.find { |r| r['name'] == tag_name } - expect(expected_tag['message']).to eq(tag_message) - expect(expected_tag['release']['description']).to eq(description) + context "when release is changed" do + before do + create(:release, :legacy, project: project, tag: tag_name) + end + + it_behaves_like "cache expired" + end + + context "when project is changed" do + before do + project.touch + end + + it_behaves_like "cache expired" + end end end + + context ":api_caching_tags flag disabled" do + before do + stub_feature_flags(api_caching_tags: false) + end + + it_behaves_like "get repository tags" + end end describe 'GET /projects/:id/repository/tags/:tag_name' do |