214
214
end
215
215
end
216
216
217
- context 'paginate array options' do
218
- shared_examples 'properly set Total header' do
217
+ if ApiPagination . config . paginator . to_sym == :kaminari
218
+ context 'paginate array options' do
219
+ let ( :paginate_array_total_count ) { 300 }
220
+ let ( :total_header ) { 300 }
221
+ let ( :count ) { 50 }
219
222
let ( :params ) do
220
223
{
221
224
paginate_array_total_count : paginate_array_total_count ,
222
225
count : count ,
223
226
}
224
227
end
225
228
226
- specify do
229
+ it 'has a properly set Total header' do
227
230
get :index_with_paginate_array_options , params : params
228
231
229
232
expect ( response . header [ 'Total' ] ) . to be_kind_of ( String )
230
233
expect ( response . header [ 'Total' ] . to_i ) . to eq total_header
231
234
end
232
235
end
233
-
234
- context 'kaminari' do
235
- around do |example |
236
- paginator = ApiPagination . config . paginator
237
- ApiPagination . config . paginator = :kaminari
238
- example . run
239
- ApiPagination . config . paginator = paginator
240
- end
241
-
242
- it_should_behave_like 'properly set Total header' do
243
- let ( :paginate_array_total_count ) { 300 }
244
- let ( :total_header ) { 300 }
245
- let ( :count ) { 50 }
246
- end
247
- end
248
-
249
- context 'will_paginate' do
250
- around do |example |
251
- paginator = ApiPagination . config . paginator
252
- ApiPagination . config . paginator = :will_paginate
253
- example . run
254
- ApiPagination . config . paginator = paginator
255
- end
256
-
257
- it_should_behave_like 'properly set Total header' do
258
- let ( :paginate_array_total_count ) { 300 }
259
- let ( :total_header ) { 50 }
260
- let ( :count ) { 50 }
261
- end
262
- end
263
236
end
264
237
265
- context 'default per page in model' do
266
- before do
267
- class Fixnum
268
- @default_per_page = 6
269
- @per_page = 6
238
+ if [ :will_paginate , :kaminari ] . include? ( ApiPagination . config . paginator . to_sym )
239
+ context 'default per page in model' do
240
+ before do
241
+ class Fixnum
242
+ @default_per_page = 6
243
+ @per_page = 6
270
244
271
- class << self
272
- attr_accessor :default_per_page , :per_page
245
+ class << self
246
+ attr_accessor :default_per_page , :per_page
247
+ end
273
248
end
274
249
end
275
- end
276
250
277
- after do
278
- class Fixnum
279
- @default_per_page = 25
280
- @per_page = 25
251
+ after do
252
+ class Fixnum
253
+ @default_per_page = 25
254
+ @per_page = 25
255
+ end
281
256
end
282
- end
283
257
284
- after :all do
285
- class Fixnum
286
- class << self
287
- undef_method :default_per_page , :per_page
258
+ after :all do
259
+ class Fixnum
260
+ class << self
261
+ undef_method :default_per_page , :per_page
262
+ end
288
263
end
289
264
end
290
- end
291
-
292
- it 'should use default per page from model' do
293
- get :index_with_no_per_page , params : { count : 100 }
294
265
295
- expect ( response . header [ 'Per-Page' ] ) . to eq ( '6' )
296
- end
266
+ it 'should use default per page from model' do
267
+ get :index_with_no_per_page , params : { count : 100 }
297
268
298
- it 'should not fail if the model yields nil for per page' do
299
- class Fixnum
300
- @default_per_page = nil
301
- @per_page = nil
269
+ expect ( response . header [ 'Per-Page' ] ) . to eq ( '6' )
302
270
end
303
271
304
- get :index_with_no_per_page , params : { count : 100 }
305
-
306
- expect ( response . header [ 'Per-Page' ] ) . to eq (
307
- case ApiPagination . config . paginator
308
- when :kaminari then Kaminari . config . default_per_page . to_s
309
- when :will_paginate then WillPaginate . per_page . to_s
272
+ it 'should not fail if the model yields nil for per page' do
273
+ class Fixnum
274
+ @default_per_page = nil
275
+ @per_page = nil
310
276
end
311
- )
277
+
278
+ get :index_with_no_per_page , params : { count : 100 }
279
+
280
+ expect ( response . header [ 'Per-Page' ] ) . to eq (
281
+ case ApiPagination . config . paginator
282
+ when :kaminari then Kaminari . config . default_per_page . to_s
283
+ when :will_paginate then WillPaginate . per_page . to_s
284
+ end
285
+ )
286
+ end
312
287
end
313
288
end
314
289
@@ -325,4 +300,4 @@ class Fixnum
325
300
end
326
301
end
327
302
end
328
- end
303
+ end
0 commit comments