mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Merge pull request #1700 from iamnader/master
Support pagination link for Kaminari when no data is returned
This commit is contained in:
commit
8c8edd6457
@ -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)
|
||||
|
||||
@ -28,7 +28,7 @@ module ActiveModelSerializers
|
||||
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
|
||||
|
||||
@ -101,6 +101,13 @@ module ActiveModelSerializers
|
||||
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)
|
||||
|
||||
@ -120,6 +127,22 @@ module ActiveModelSerializers
|
||||
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)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user