File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed
lib/active_model_serializers/adapter/json_api Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ Features:
46
46
- [ #1340 ] ( https://github.com/rails-api/active_model_serializers/pull/1340 ) Add support for resource-level meta. (@beauby )
47
47
48
48
Fixes:
49
+ - [ #1700 ] ( https://github.com/rails-api/active_model_serializers/pull/1700 ) Support pagination link for Kaminari when no data is returned
49
50
- [ #1657 ] ( https://github.com/rails-api/active_model_serializers/pull/1657 ) Add missing missing require "active_support/json". (@andreaseger )
50
51
- [ #1661 ] ( https://github.com/rails-api/active_model_serializers/pull/1661 ) Fixes ` read_attribute_for_serialization ` not
51
52
seeing methods defined in serialization superclass (#1653 , #1658 , #1660 ), introduced in #1650 . (@bf4 )
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ def as_json
28
28
private
29
29
30
30
def pages_from
31
- return { } if collection . total_pages = = FIRST_PAGE
31
+ return { } if collection . total_pages < = FIRST_PAGE
32
32
33
33
{ } . tap do |pages |
34
34
pages [ :self ] = collection . current_page
Original file line number Diff line number Diff line change @@ -101,6 +101,13 @@ def expected_response_with_last_page_pagination_links
101
101
end
102
102
end
103
103
104
+ def expected_response_with_no_data_pagination_links
105
+ { } . tap do |hash |
106
+ hash [ :data ] = [ ]
107
+ hash [ :links ] = { }
108
+ end
109
+ end
110
+
104
111
def test_pagination_links_using_kaminari
105
112
adapter = load_adapter ( using_kaminari , mock_request )
106
113
@@ -120,6 +127,22 @@ def test_pagination_links_with_additional_params
120
127
adapter . serializable_hash
121
128
end
122
129
130
+ def test_pagination_links_when_zero_results_kaminari
131
+ @array = [ ]
132
+
133
+ adapter = load_adapter ( using_kaminari ( 1 ) , mock_request )
134
+
135
+ assert_equal expected_response_with_no_data_pagination_links , adapter . serializable_hash
136
+ end
137
+
138
+ def test_pagination_links_when_zero_results_will_paginate
139
+ @array = [ ]
140
+
141
+ adapter = load_adapter ( using_will_paginate ( 1 ) , mock_request )
142
+
143
+ assert_equal expected_response_with_no_data_pagination_links , adapter . serializable_hash
144
+ end
145
+
123
146
def test_last_page_pagination_links_using_kaminari
124
147
adapter = load_adapter ( using_kaminari ( 3 ) , mock_request )
125
148
You can’t perform that action at this time.
0 commit comments