From 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 20 Aug 2020 18:42:06 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-3-stable-ee --- spec/requests/api/branches_spec.rb | 82 +++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 37 deletions(-) (limited to 'spec/requests/api/branches_spec.rb') diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index 46acd92803f..4b9b82b3a5b 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -39,9 +39,11 @@ RSpec.describe API::Branches do end context 'with branch_list_keyset_pagination feature off' do - context 'with legacy pagination params' do + let(:base_params) { {} } + + context 'with offset pagination params' do it 'returns the repository branches' do - get api(route, current_user), params: { per_page: 100 } + get api(route, current_user), params: base_params.merge(per_page: 100) expect(response).to have_gitlab_http_status(:ok) expect(response).to match_response_schema('public_api/v4/branches') @@ -53,7 +55,7 @@ RSpec.describe API::Branches do it 'determines only a limited number of merged branch names' do expect(API::Entities::Branch).to receive(:represent).with(anything, has_up_to_merged_branch_names_count(2)).and_call_original - get api(route, current_user), params: { per_page: 2 } + get api(route, current_user), params: base_params.merge(per_page: 2) expect(response).to have_gitlab_http_status(:ok) expect(json_response.count).to eq 2 @@ -64,7 +66,7 @@ RSpec.describe API::Branches do it 'merge status matches reality on paginated input' do expected_first_branch_name = project.repository.branches_sorted_by('name')[20].name - get api(route, current_user), params: { per_page: 20, page: 2 } + get api(route, current_user), params: base_params.merge(per_page: 20, page: 2) expect(response).to have_gitlab_http_status(:ok) expect(json_response.count).to eq 20 @@ -74,11 +76,11 @@ RSpec.describe API::Branches do end end - context 'with gitaly pagination params ' do + context 'with gitaly pagination params' do it 'merge status matches reality on paginated input' do expected_first_branch_name = project.repository.branches_sorted_by('name').first.name - get api(route, current_user), params: { per_page: 20, page_token: 'feature' } + get api(route, current_user), params: base_params.merge(per_page: 20, page_token: 'feature') expect(response).to have_gitlab_http_status(:ok) expect(json_response.count).to eq 20 @@ -91,52 +93,58 @@ RSpec.describe API::Branches do context 'with branch_list_keyset_pagination feature on' do before do - stub_feature_flags(branch_list_keyset_pagination: true) + stub_feature_flags(branch_list_keyset_pagination: project) end - context 'with gitaly pagination params ' do - it 'returns the repository branches' do - get api(route, current_user), params: { per_page: 100 } + context 'with keyset pagination option' do + let(:base_params) { { pagination: 'keyset' } } - expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('public_api/v4/branches') - branch_names = json_response.map { |x| x['name'] } - expect(branch_names).to match_array(project.repository.branch_names) - end + context 'with gitaly pagination params ' do + it 'returns the repository branches' do + get api(route, current_user), params: base_params.merge(per_page: 100) - it 'determines only a limited number of merged branch names' do - expect(API::Entities::Branch).to receive(:represent).with(anything, has_up_to_merged_branch_names_count(2)).and_call_original + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('public_api/v4/branches') + expect(response.headers).not_to include('Link', 'Links') + branch_names = json_response.map { |x| x['name'] } + expect(branch_names).to match_array(project.repository.branch_names) + end - get api(route, current_user), params: { per_page: 2 } + it 'determines only a limited number of merged branch names' do + expect(API::Entities::Branch).to receive(:represent).with(anything, has_up_to_merged_branch_names_count(2)).and_call_original - expect(response).to have_gitlab_http_status(:ok) - expect(json_response.count).to eq 2 + get api(route, current_user), params: base_params.merge(per_page: 2) - check_merge_status(json_response) - end + expect(response).to have_gitlab_http_status(:ok) + expect(response.headers).to include('Link', 'Links') + expect(json_response.count).to eq 2 - it 'merge status matches reality on paginated input' do - expected_first_branch_name = project.repository.branches_sorted_by('name').drop_while { |b| b.name <= 'feature' }.first.name + check_merge_status(json_response) + end - get api(route, current_user), params: { per_page: 20, page_token: 'feature' } + it 'merge status matches reality on paginated input' do + expected_first_branch_name = project.repository.branches_sorted_by('name').drop_while { |b| b.name <= 'feature' }.first.name - expect(response).to have_gitlab_http_status(:ok) - expect(json_response.count).to eq 20 - expect(json_response.first['name']).to eq(expected_first_branch_name) + get api(route, current_user), params: base_params.merge(per_page: 20, page_token: 'feature') - check_merge_status(json_response) + expect(response).to have_gitlab_http_status(:ok) + expect(json_response.count).to eq 20 + expect(json_response.first['name']).to eq(expected_first_branch_name) + + check_merge_status(json_response) + end end - end - context 'with legacy pagination params' do - it 'ignores legacy pagination params' do - expected_first_branch_name = project.repository.branches_sorted_by('name').first.name - get api(route, current_user), params: { per_page: 20, page: 2 } + context 'with offset pagination params' do + it 'ignores legacy pagination params' do + expected_first_branch_name = project.repository.branches_sorted_by('name').first.name + get api(route, current_user), params: base_params.merge(per_page: 20, page: 2) - expect(response).to have_gitlab_http_status(:ok) - expect(json_response.first['name']).to eq(expected_first_branch_name) + expect(response).to have_gitlab_http_status(:ok) + expect(json_response.first['name']).to eq(expected_first_branch_name) - check_merge_status(json_response) + check_merge_status(json_response) + end end end end -- cgit v1.2.1