Skip to content

Commit 60af4d2

Browse files
committed
Fix all the specs
1 parent ddb87b0 commit 60af4d2

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ gem 'pagy', require: false
99

1010
gem 'sqlite3', require: false
1111
gem 'sequel', require: false
12+
gem 'pry-suite'

lib/api-pagination.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,23 @@ def paginate_with_kaminari(collection, options, paginate_array_options = {})
8989
end
9090

9191
collection = Kaminari.paginate_array(collection, paginate_array_options) if collection.is_a?(Array)
92-
collection.page(options[:page]).per(options[:per_page])
92+
[collection.page(options[:page]).per(options[:per_page]), nil]
9393
end
9494

9595
def paginate_with_will_paginate(collection, options)
9696
if options[:per_page] <= 0
9797
options[:per_page] = default_per_page_for_will_paginate(collection)
9898
end
9999

100-
if defined?(Sequel::Dataset) && collection.kind_of?(Sequel::Dataset)
100+
collection = if defined?(Sequel::Dataset) && collection.kind_of?(Sequel::Dataset)
101101
collection.paginate(options[:page], options[:per_page])
102102
else
103103
supported_options = [:page, :per_page, :total_entries]
104104
options = options.dup.keep_if { |k,v| supported_options.include?(k.to_sym) }
105105
collection.paginate(options)
106106
end
107+
108+
[collection, nil]
107109
end
108110

109111
def get_default_per_page_for_kaminari(collection)

spec/api-pagination_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
end
2323

2424
describe '.pages_from' do
25-
subject {described_class.pages_from collection}
25+
subject { described_class.pages_from(collection) }
2626

2727
context 'on empty collection' do
28-
let(:collection) {ApiPagination.paginate [], page: 1}
28+
let(:collection) { ApiPagination.paginate([], page: 1).first }
2929

30-
it {is_expected.to be_empty}
30+
it { is_expected.to be_empty }
3131
end
3232
end
3333
end
@@ -37,14 +37,14 @@
3737
context 'Using will_paginate' do
3838
context 'passing in total_entries in options' do
3939
it 'should set total_entries using the passed in value' do
40-
paginated_collection = ApiPagination.paginate(collection, total_entries: 3000)
40+
paginated_collection = ApiPagination.paginate(collection, total_entries: 3000).first
4141
expect(paginated_collection.total_entries).to eq(3000)
4242
end
4343
end
4444

4545
context 'passing in collection only' do
4646
it 'should set total_entries using the size of the collection ' do
47-
paginated_collection = ApiPagination.paginate(collection)
47+
paginated_collection = ApiPagination.paginate(collection).first
4848
expect(paginated_collection.total_entries).to eq(100)
4949
end
5050
end

spec/sequel_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
end
2424

2525
it 'returns a Sequel::Dataset' do
26-
collection = ApiPagination.paginate(people)
26+
collection = ApiPagination.paginate(people).first
2727
expect(collection.kind_of?(Sequel::Dataset)).to be_truthy
2828
end
2929
end
3030
end
31-

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
require ENV['PAGINATOR']
1717
ApiPagination.config.paginator = ENV['PAGINATOR'].to_sym
1818

19-
require 'will_paginate/array' if ENV['PAGINATOR'] == :will_paginate
19+
require 'will_paginate/array' if ENV['PAGINATOR'].to_sym == :will_paginate
2020

2121
RSpec.configure do |config|
2222
config.include Rack::Test::Methods

0 commit comments

Comments
 (0)