File tree Expand file tree Collapse file tree 6 files changed +33
-4
lines changed Expand file tree Collapse file tree 6 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -45,12 +45,12 @@ def paginator
45
45
end
46
46
47
47
def per_page_header
48
- warn "[DEPRECATION] ApiPagination.paginator is deprecated. Please use ApiPagination.config.per_page_header"
48
+ warn "[DEPRECATION] ApiPagination.per_page_header is deprecated. Please use ApiPagination.config.per_page_header"
49
49
config . per_page_header
50
50
end
51
51
52
52
def total_header
53
- warn "[DEPRECATION] ApiPagination.paginator is deprecated. Please use ApiPagination.config.total_header"
53
+ warn "[DEPRECATION] ApiPagination.total_header is deprecated. Please use ApiPagination.config.total_header"
54
54
config . total_header
55
55
end
56
56
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ class Configuration
6
6
7
7
attr_accessor :page_header
8
8
9
+ attr_accessor :include_total
10
+
9
11
def configure ( &block )
10
12
yield self
11
13
end
@@ -14,6 +16,7 @@ def initialize
14
16
@total_header = 'Total'
15
17
@per_page_header = 'Per-Page'
16
18
@page_header = nil
19
+ @include_total = true
17
20
end
18
21
19
22
def paginator
Original file line number Diff line number Diff line change @@ -23,9 +23,10 @@ def paginate(collection)
23
23
total_header = ApiPagination . config . total_header
24
24
per_page_header = ApiPagination . config . per_page_header
25
25
page_header = ApiPagination . config . page_header
26
+ include_total = ApiPagination . config . include_total
26
27
27
28
header 'Link' , links . join ( ', ' ) unless links . empty?
28
- header total_header , ApiPagination . total_from ( collection )
29
+ header total_header , ApiPagination . total_from ( collection ) if include_total
29
30
header per_page_header , options [ :per_page ] . to_s
30
31
header page_header , options [ :page ] . to_s unless page_header . nil?
31
32
Original file line number Diff line number Diff line change @@ -42,9 +42,10 @@ def _paginate_collection(collection, options={})
42
42
total_header = ApiPagination . config . total_header
43
43
per_page_header = ApiPagination . config . per_page_header
44
44
page_header = ApiPagination . config . page_header
45
+ include_total = ApiPagination . config . include_total
45
46
46
47
headers [ 'Link' ] = links . join ( ', ' ) unless links . empty?
47
- headers [ total_header ] = ApiPagination . total_from ( collection )
48
+ headers [ total_header ] = ApiPagination . total_from ( collection ) if include_total
48
49
headers [ per_page_header ] = options [ :per_page ] . to_s
49
50
headers [ page_header ] = options [ :page ] . to_s unless page_header . nil?
50
51
Original file line number Diff line number Diff line change 110
110
end
111
111
end
112
112
113
+ context 'configured not to include the total' do
114
+ before { ApiPagination . config . include_total = false }
115
+
116
+ it 'should not include a Total header' do
117
+ get '/numbers' , count : 10
118
+
119
+ expect ( last_response . header [ 'Total' ] ) . to be_nil
120
+ end
121
+
122
+ after { ApiPagination . config . include_total = true }
123
+ end
124
+
113
125
context 'with query string including array parameter' do
114
126
before do
115
127
get '/numbers' , { count : 100 , parity : [ 'odd' , 'even' ] }
Original file line number Diff line number Diff line change 111
111
expect ( page ) . to eq ( 1 )
112
112
end
113
113
end
114
+
115
+ context 'configured not to include the total' do
116
+ before { ApiPagination . config . include_total = false }
117
+
118
+ it 'should not include a Total header' do
119
+ get :index , count : 10
120
+
121
+ expect ( response . header [ 'Total' ] ) . to be_nil
122
+ end
123
+
124
+ after { ApiPagination . config . include_total = true }
125
+ end
114
126
end
115
127
end
You can’t perform that action at this time.
0 commit comments