mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
return complete URIs on pagination links
This commit is contained in:
@@ -47,7 +47,10 @@ module ActionController
|
||||
tests PaginationTestController
|
||||
|
||||
def test_render_pagination_links_with_will_paginate
|
||||
expected_links = {"first"=>"?page=1&per_page=1", "prev"=>"?page=1&per_page=1", "next"=>"?page=3&per_page=1", "last"=>"?page=3&per_page=1"}
|
||||
expected_links = {"first"=>"http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_will_paginate?page=1&per_page=1",
|
||||
"prev"=>"http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_will_paginate?page=1&per_page=1",
|
||||
"next"=>"http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_will_paginate?page=3&per_page=1",
|
||||
"last"=>"http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_will_paginate?page=3&per_page=1"}
|
||||
|
||||
get :render_pagination_using_will_paginate, page: 2, per_page: 1
|
||||
response = JSON.parse(@response.body)
|
||||
@@ -55,21 +58,26 @@ module ActionController
|
||||
end
|
||||
|
||||
def test_render_only_last_and_next_pagination_links
|
||||
expected_links = {"next"=>"?page=2&per_page=2", "last"=>"?page=2&per_page=2"}
|
||||
expected_links = {"next"=>"http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_will_paginate?page=2&per_page=2",
|
||||
"last"=>"http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_will_paginate?page=2&per_page=2"}
|
||||
get :render_pagination_using_will_paginate, page: 1, per_page: 2
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
|
||||
def test_render_pagination_links_with_kaminari
|
||||
expected_links = {"first"=>"?page=1&per_page=1", "prev"=>"?page=1&per_page=1", "next"=>"?page=3&per_page=1", "last"=>"?page=3&per_page=1"}
|
||||
expected_links = {"first"=>"http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_kaminari?page=1&per_page=1",
|
||||
"prev"=>"http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_kaminari?page=1&per_page=1",
|
||||
"next"=>"http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_kaminari?page=3&per_page=1",
|
||||
"last"=>"http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_kaminari?page=3&per_page=1"}
|
||||
get :render_pagination_using_kaminari, page: 2, per_page: 1
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
|
||||
def test_render_only_prev_and_first_pagination_links
|
||||
expected_links = {"first"=>"?page=1&per_page=1", "prev"=>"?page=2&per_page=1"}
|
||||
expected_links = {"first"=>"http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_kaminari?page=1&per_page=1",
|
||||
"prev"=>"http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_kaminari?page=2&per_page=1"}
|
||||
get :render_pagination_using_kaminari, page: 3, per_page: 1
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
|
||||
@@ -404,6 +404,9 @@ module ActionController
|
||||
def use_adapter?
|
||||
false
|
||||
end
|
||||
def original_url
|
||||
"http://example.com/"
|
||||
end
|
||||
}.new
|
||||
assert_match /adapter: false/, (capture(:stderr) {
|
||||
controller.get_serializer(Profile.new)
|
||||
@@ -415,6 +418,9 @@ module ActionController
|
||||
def use_adapter?
|
||||
true
|
||||
end
|
||||
def original_url
|
||||
"http://example.com/"
|
||||
end
|
||||
}.new
|
||||
assert_equal "", (capture(:stderr) {
|
||||
controller.get_serializer(Profile.new)
|
||||
|
||||
@@ -50,23 +50,23 @@ module ActiveModel
|
||||
}
|
||||
}],
|
||||
links:{
|
||||
first:"?page=1&per_page=1",
|
||||
prev:"?page=1&per_page=1",
|
||||
next:"?page=3&per_page=1",
|
||||
last:"?page=3&per_page=1"
|
||||
first: "http://example.com?page=1&per_page=1",
|
||||
prev: "http://example.com?page=1&per_page=1",
|
||||
next: "http://example.com?page=3&per_page=1",
|
||||
last: "http://example.com?page=3&per_page=1"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_pagination_links_using_kaminari
|
||||
serializer = ArraySerializer.new(using_kaminari, pagination: true)
|
||||
serializer = ArraySerializer.new(using_kaminari, pagination: true, original_url: "http://example.com")
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
||||
|
||||
assert_equal expected_response_with_pagination_links, adapter.serializable_hash
|
||||
end
|
||||
|
||||
def test_pagination_links_using_will_paginate
|
||||
serializer = ArraySerializer.new(using_will_paginate, pagination: true)
|
||||
serializer = ArraySerializer.new(using_will_paginate, pagination: true, original_url: "http://example.com")
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
||||
|
||||
assert_equal expected_response_with_pagination_links, adapter.serializable_hash
|
||||
|
||||
@@ -95,7 +95,7 @@ module ActiveModel
|
||||
|
||||
def test_pagination_attr_readers
|
||||
serializer = ArraySerializer.new(@resource, pagination: true)
|
||||
assert_equal serializer.pagination, true
|
||||
assert_equal serializer.options[:pagination], true
|
||||
end
|
||||
|
||||
def test_resource
|
||||
|
||||
Reference in New Issue
Block a user