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 d2df579
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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 d2df579

Please sign in to comment.