mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Disable pagination links via config
This commit is contained in:
parent
050060478d
commit
19b5abf66e
@ -13,6 +13,7 @@ Features:
|
|||||||
- [#1791](https://github.com/rails-api/active_model_serializers/pull/1791) (@bf4, @youroff, @NullVoxPopuli)
|
- [#1791](https://github.com/rails-api/active_model_serializers/pull/1791) (@bf4, @youroff, @NullVoxPopuli)
|
||||||
- Added `jsonapi_namespace_separator` config option.
|
- Added `jsonapi_namespace_separator` config option.
|
||||||
- [#1889](https://github.com/rails-api/active_model_serializers/pull/1889) Support key transformation for Attributes adapter (@iancanderson, @danbee)
|
- [#1889](https://github.com/rails-api/active_model_serializers/pull/1889) Support key transformation for Attributes adapter (@iancanderson, @danbee)
|
||||||
|
- [#1917](https://github.com/rails-api/active_model_serializers/pull/1917) Add `jsonapi_pagination_links_enabled` configuration option (@richmolj)
|
||||||
|
|
||||||
Fixes:
|
Fixes:
|
||||||
|
|
||||||
|
|||||||
@ -52,6 +52,7 @@ module ActiveModel
|
|||||||
# rubocop:enable Metrics/CyclomaticComplexity
|
# rubocop:enable Metrics/CyclomaticComplexity
|
||||||
|
|
||||||
def paginated?
|
def paginated?
|
||||||
|
ActiveModelSerializers.config.jsonapi_pagination_links_enabled &&
|
||||||
object.respond_to?(:current_page) &&
|
object.respond_to?(:current_page) &&
|
||||||
object.respond_to?(:total_pages) &&
|
object.respond_to?(:total_pages) &&
|
||||||
object.respond_to?(:size)
|
object.respond_to?(:size)
|
||||||
|
|||||||
@ -22,6 +22,7 @@ module ActiveModel
|
|||||||
config.default_includes = '*'
|
config.default_includes = '*'
|
||||||
config.adapter = :attributes
|
config.adapter = :attributes
|
||||||
config.key_transform = nil
|
config.key_transform = nil
|
||||||
|
config.jsonapi_pagination_links_enabled = true
|
||||||
config.jsonapi_resource_type = :plural
|
config.jsonapi_resource_type = :plural
|
||||||
config.jsonapi_namespace_separator = '-'.freeze
|
config.jsonapi_namespace_separator = '-'.freeze
|
||||||
config.jsonapi_version = '1.0'
|
config.jsonapi_version = '1.0'
|
||||||
|
|||||||
@ -76,7 +76,7 @@ module ActiveModelSerializers
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def expected_response_without_pagination_links
|
def expected_response_when_unpaginatable
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -87,6 +87,12 @@ module ActiveModelSerializers
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expected_response_without_pagination_links
|
||||||
|
{}.tap do |hash|
|
||||||
|
hash[:data] = data.values.flatten[2..3]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def expected_response_with_pagination_links_and_additional_params
|
def expected_response_with_pagination_links_and_additional_params
|
||||||
new_links = links[:links].each_with_object({}) { |(key, value), hash| hash[key] = "#{value}&test=test" }
|
new_links = links[:links].each_with_object({}) { |(key, value), hash| hash[key] = "#{value}&test=test" }
|
||||||
{}.tap do |hash|
|
{}.tap do |hash|
|
||||||
@ -159,7 +165,7 @@ module ActiveModelSerializers
|
|||||||
def test_not_showing_pagination_links
|
def test_not_showing_pagination_links
|
||||||
adapter = load_adapter(@array, mock_request)
|
adapter = load_adapter(@array, mock_request)
|
||||||
|
|
||||||
assert_equal expected_response_without_pagination_links, adapter.serializable_hash
|
assert_equal expected_response_when_unpaginatable, adapter.serializable_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_raises_descriptive_error_when_serialization_context_unset
|
def test_raises_descriptive_error_when_serialization_context_unset
|
||||||
@ -172,6 +178,15 @@ module ActiveModelSerializers
|
|||||||
assert_equal exception_class, exception.class
|
assert_equal exception_class, exception.class
|
||||||
assert_match(/CollectionSerializer#paginated\?/, exception.message)
|
assert_match(/CollectionSerializer#paginated\?/, exception.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_pagination_links_not_present_when_disabled
|
||||||
|
ActiveModel::Serializer.config.jsonapi_pagination_links_enabled = false
|
||||||
|
adapter = load_adapter(using_kaminari, mock_request)
|
||||||
|
|
||||||
|
assert_equal expected_response_without_pagination_links, adapter.serializable_hash
|
||||||
|
ensure
|
||||||
|
ActiveModel::Serializer.config.jsonapi_pagination_links_enabled = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user