diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/lib/gitlab/pagination/offset_header_builder_spec.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/lib/gitlab/pagination/offset_header_builder_spec.rb')
-rw-r--r-- | spec/lib/gitlab/pagination/offset_header_builder_spec.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/lib/gitlab/pagination/offset_header_builder_spec.rb b/spec/lib/gitlab/pagination/offset_header_builder_spec.rb new file mode 100644 index 00000000000..a415bad5135 --- /dev/null +++ b/spec/lib/gitlab/pagination/offset_header_builder_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +RSpec.describe Gitlab::Pagination::OffsetHeaderBuilder do + let(:request) { double(url: 'http://localhost') } + let(:request_context) { double(header: nil, params: { per_page: 5 }, request: request) } + + subject do + described_class.new( + request_context: request_context, per_page: 5, page: 2, + next_page: 3, prev_page: 1, total: 10, total_pages: 3 + ) + end + + describe '#execute' do + let(:basic_links) do + %{<http://localhost?page=1&per_page=5>; rel="prev", <http://localhost?page=3&per_page=5>; rel="next", <http://localhost?page=1&per_page=5>; rel="first"} + end + + let(:last_link) do + %{, <http://localhost?page=3&per_page=5>; rel="last"} + end + + def expect_basic_headers + expect(request_context).to receive(:header).with('X-Per-Page', '5') + expect(request_context).to receive(:header).with('X-Page', '2') + expect(request_context).to receive(:header).with('X-Next-Page', '3') + expect(request_context).to receive(:header).with('X-Prev-Page', '1') + expect(request_context).to receive(:header).with('Link', basic_links + last_link) + end + + it 'sets headers to request context' do + expect_basic_headers + expect(request_context).to receive(:header).with('X-Total', '10') + expect(request_context).to receive(:header).with('X-Total-Pages', '3') + + subject.execute + end + + context 'exclude total headers' do + it 'does not set total headers to request context' do + expect_basic_headers + expect(request_context).not_to receive(:header) + + subject.execute(exclude_total_headers: true) + end + end + + context 'pass data without counts' do + let(:last_link) { '' } + + it 'does not set total headers to request context' do + expect_basic_headers + expect(request_context).not_to receive(:header) + + subject.execute(data_without_counts: true) + end + end + end +end |