Skip to content

Commit 5c6309f

Browse files
committed
reconcile with master
1 parent fa415a6 commit 5c6309f

File tree

1 file changed

+43
-68
lines changed

1 file changed

+43
-68
lines changed

spec/rails_spec.rb

Lines changed: 43 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -214,101 +214,76 @@
214214
end
215215
end
216216

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 }
219222
let(:params) do
220223
{
221224
paginate_array_total_count: paginate_array_total_count,
222225
count: count,
223226
}
224227
end
225228

226-
specify do
229+
it 'has a properly set Total header' do
227230
get :index_with_paginate_array_options, params: params
228231

229232
expect(response.header['Total']).to be_kind_of(String)
230233
expect(response.header['Total'].to_i).to eq total_header
231234
end
232235
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
263236
end
264237

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
270244

271-
class << self
272-
attr_accessor :default_per_page, :per_page
245+
class << self
246+
attr_accessor :default_per_page, :per_page
247+
end
273248
end
274249
end
275-
end
276250

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
281256
end
282-
end
283257

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
288263
end
289264
end
290-
end
291-
292-
it 'should use default per page from model' do
293-
get :index_with_no_per_page, params: {count: 100}
294265

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}
297268

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')
302270
end
303271

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
310276
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
312287
end
313288
end
314289

@@ -325,4 +300,4 @@ class Fixnum
325300
end
326301
end
327302
end
328-
end
303+
end

0 commit comments

Comments
 (0)