Skip to content

Commit dbe1d99

Browse files
authored
Merge pull request #78 from sandrew/master
Kaminari 1.0 last_page? behavior fix
2 parents 18eccd6 + a099535 commit dbe1d99

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/api-pagination.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def pages_from(collection)
2525
pages[:prev] = collection.current_page - 1
2626
end
2727

28-
unless collection.last_page?
28+
unless collection.last_page? || (ApiPagination.config.paginator == :kaminari && collection.out_of_range?)
2929
pages[:last] = collection.total_pages
3030
pages[:next] = collection.current_page + 1
3131
end

spec/api-pagination_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,15 @@
2626
}
2727
)
2828
end
29+
30+
describe '.pages_from' do
31+
subject { described_class.pages_from collection }
32+
33+
context 'on empty collection' do
34+
let(:collection) { ApiPagination.paginate [], page: 1 }
35+
36+
it { is_expected.to be_empty }
37+
end
38+
end
2939
end
3040
end

0 commit comments

Comments
 (0)