mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
this fixes a bug where an invalid next link appears if the current page is greater than total_pages
adding tests fixing rubocop violation
This commit is contained in:
@@ -90,6 +90,18 @@ module ActiveModelSerializers
|
||||
}
|
||||
end
|
||||
|
||||
def greater_than_last_page_links
|
||||
{
|
||||
links: {
|
||||
self: "#{URI}?page%5Bnumber%5D=4&page%5Bsize%5D=2",
|
||||
first: "#{URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
||||
prev: "#{URI}?page%5Bnumber%5D=3&page%5Bsize%5D=2",
|
||||
next: nil,
|
||||
last: "#{URI}?page%5Bnumber%5D=3&page%5Bsize%5D=2"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def expected_response_when_unpaginatable
|
||||
data
|
||||
end
|
||||
@@ -122,6 +134,13 @@ module ActiveModelSerializers
|
||||
end
|
||||
end
|
||||
|
||||
def expected_response_with_greater_than_last_page_pagination_links
|
||||
{}.tap do |hash|
|
||||
hash[:data] = []
|
||||
hash.merge! greater_than_last_page_links
|
||||
end
|
||||
end
|
||||
|
||||
def expected_response_with_empty_collection_pagination_links
|
||||
{}.tap do |hash|
|
||||
hash[:data] = []
|
||||
@@ -141,6 +160,18 @@ module ActiveModelSerializers
|
||||
assert_equal expected_response_with_pagination_links, adapter.serializable_hash
|
||||
end
|
||||
|
||||
def test_pagination_links_invalid_current_page_using_kaminari
|
||||
adapter = load_adapter(using_kaminari(4), mock_request)
|
||||
|
||||
assert_equal expected_response_with_greater_than_last_page_pagination_links, adapter.serializable_hash
|
||||
end
|
||||
|
||||
def test_pagination_links_invalid_current_page_using_will_paginate
|
||||
adapter = load_adapter(using_will_paginate(4), mock_request)
|
||||
|
||||
assert_equal expected_response_with_greater_than_last_page_pagination_links, adapter.serializable_hash
|
||||
end
|
||||
|
||||
def test_pagination_links_with_additional_params
|
||||
adapter = load_adapter(using_will_paginate, mock_request(test: 'test'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user