diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/lib/gitlab/pagination/gitaly_keyset_pager_spec.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/lib/gitlab/pagination/gitaly_keyset_pager_spec.rb')
-rw-r--r-- | spec/lib/gitlab/pagination/gitaly_keyset_pager_spec.rb | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/spec/lib/gitlab/pagination/gitaly_keyset_pager_spec.rb b/spec/lib/gitlab/pagination/gitaly_keyset_pager_spec.rb index 156a440833c..132a0e9ca78 100644 --- a/spec/lib/gitlab/pagination/gitaly_keyset_pager_spec.rb +++ b/spec/lib/gitlab/pagination/gitaly_keyset_pager_spec.rb @@ -57,17 +57,45 @@ RSpec.describe Gitlab::Pagination::GitalyKeysetPager do end context 'with branch_list_keyset_pagination feature on' do + let(:fake_request) { double(url: "#{incoming_api_projects_url}?#{query.to_query}") } + let(:branch1) { double 'branch', name: 'branch1' } + let(:branch2) { double 'branch', name: 'branch2' } + let(:branch3) { double 'branch', name: 'branch3' } + before do stub_feature_flags(branch_list_keyset_pagination: project) end context 'without keyset pagination option' do - it_behaves_like 'offset pagination' + context 'when first page is requested' do + let(:branches) { [branch1, branch2, branch3] } + + it 'keyset pagination is used with offset headers' do + allow(request_context).to receive(:request).and_return(fake_request) + allow(project.repository).to receive(:branch_count).and_return(branches.size) + + expect(finder).to receive(:execute).with(gitaly_pagination: true).and_return(branches) + expect(request_context).to receive(:header).with('X-Per-Page', '2') + expect(request_context).to receive(:header).with('X-Page', '1') + expect(request_context).to receive(:header).with('X-Next-Page', '2') + expect(request_context).to receive(:header).with('X-Prev-Page', '') + expect(request_context).to receive(:header).with('Link', kind_of(String)) + expect(request_context).to receive(:header).with('X-Total', '3') + expect(request_context).to receive(:header).with('X-Total-Pages', '2') + + pager.paginate(finder) + end + end + + context 'when second page is requested' do + let(:base_query) { { per_page: 2, page: 2 } } + + it_behaves_like 'offset pagination' + end end context 'with keyset pagination option' do let(:query) { base_query.merge(pagination: 'keyset') } - let(:fake_request) { double(url: "#{incoming_api_projects_url}?#{query.to_query}") } before do allow(request_context).to receive(:request).and_return(fake_request) @@ -75,8 +103,6 @@ RSpec.describe Gitlab::Pagination::GitalyKeysetPager do end context 'when next page could be available' do - let(:branch1) { double 'branch', name: 'branch1' } - let(:branch2) { double 'branch', name: 'branch2' } let(:branches) { [branch1, branch2] } let(:expected_next_page_link) { %Q(<#{incoming_api_projects_url}?#{query.merge(page_token: branch2.name).to_query}>; rel="next") } @@ -90,7 +116,6 @@ RSpec.describe Gitlab::Pagination::GitalyKeysetPager do end context 'when the current page is the last page' do - let(:branch1) { double 'branch', name: 'branch1' } let(:branches) { [branch1] } it 'uses keyset pagination without link headers' do |