1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
|