Skip to content

Commit

Permalink
Support pagination link for Kaminari when no data is returned
Browse files Browse the repository at this point in the history
  • Loading branch information
iamnader committed Apr 22, 2016
1 parent b4e2ac3 commit 23141af
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Breaking changes:
- [#1574](https://github.com/rails-api/active_model_serializers/pull/1574) Default key case for the JsonApi adapter changed to dashed. (@remear)

Features:

- [#1687](https://github.com/rails-api/active_model_serializers/pull/1687) Only calculate `_cache_digest` (in `cache_key`) when `skip_digest` is false. (@bf4)
- [#1647](https://github.com/rails-api/active_model_serializers/pull/1647) Restrict usage of `serializable_hash` options
to the ActiveModel::Serialization and ActiveModel::Serializers::JSON interface. (@bf4)
Expand Down Expand Up @@ -46,6 +47,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

0 comments on commit 23141af

Please sign in to comment.