Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pagination link for Kaminari when no data is returned #1700

Merged
merged 1 commit into from
Apr 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Features:
- [#1340](https://github.com/rails-api/active_model_serializers/pull/1340) Add support for resource-level meta. (@beauby)

Fixes:
- [#1700](https://github.com/rails-api/active_model_serializers/pull/1700) Support pagination link for Kaminari when no data is returned
- [#1657](https://github.com/rails-api/active_model_serializers/pull/1657) Add missing missing require "active_support/json". (@andreaseger)
- [#1661](https://github.com/rails-api/active_model_serializers/pull/1661) Fixes `read_attribute_for_serialization` not
seeing methods defined in serialization superclass (#1653, #1658, #1660), introduced in #1650. (@bf4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def as_json
private

def pages_from
return {} if collection.total_pages == FIRST_PAGE
return {} if collection.total_pages <= FIRST_PAGE

{}.tap do |pages|
pages[:self] = collection.current_page
Expand Down
23 changes: 23 additions & 0 deletions test/adapter/json_api/pagination_links_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ def expected_response_with_last_page_pagination_links
end
end

def expected_response_with_no_data_pagination_links
{}.tap do |hash|
hash[:data] = []
hash[:links] = {}
end
end

def test_pagination_links_using_kaminari
adapter = load_adapter(using_kaminari, mock_request)

Expand All @@ -120,6 +127,22 @@ def test_pagination_links_with_additional_params
adapter.serializable_hash
end

def test_pagination_links_when_zero_results_kaminari
@array = []

adapter = load_adapter(using_kaminari(1), mock_request)

assert_equal expected_response_with_no_data_pagination_links, adapter.serializable_hash
end

def test_pagination_links_when_zero_results_will_paginate
@array = []

adapter = load_adapter(using_will_paginate(1), mock_request)

assert_equal expected_response_with_no_data_pagination_links, adapter.serializable_hash
end

def test_last_page_pagination_links_using_kaminari
adapter = load_adapter(using_kaminari(3), mock_request)

Expand Down