mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Fixed a documentation error regarding adapter key constant, added tests
for SerializableResource::use_adapter?
This commit is contained in:
parent
f32c0d97d5
commit
68f09e59c4
@ -3,6 +3,7 @@
|
|||||||
Breaking changes:
|
Breaking changes:
|
||||||
Features:
|
Features:
|
||||||
Fixes:
|
Fixes:
|
||||||
|
- [#1501](https://github.com/rails-api/active_model_serializers/pull/1501) Adds tests for SerializableResource::use_adapter?,doc typos (@domitian)
|
||||||
- [#1488](https://github.com/rails-api/active_model_serializers/pull/1488) Require ActiveSupport's string inflections (@nate00)
|
- [#1488](https://github.com/rails-api/active_model_serializers/pull/1488) Require ActiveSupport's string inflections (@nate00)
|
||||||
Misc:
|
Misc:
|
||||||
|
|
||||||
|
|||||||
@ -56,7 +56,7 @@ High-level overview:
|
|||||||
- `:each_serializer` specifies the serializer for each resource in the collection.
|
- `:each_serializer` specifies the serializer for each resource in the collection.
|
||||||
- For a single resource, the `:serializer` option is the resource serializer.
|
- For a single resource, the `:serializer` option is the resource serializer.
|
||||||
- Options are partitioned in serializer options and adapter options. Keys for adapter options are specified by
|
- Options are partitioned in serializer options and adapter options. Keys for adapter options are specified by
|
||||||
[`ADAPTER_OPTIONS`](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializable_resource.rb#L4).
|
[`ADAPTER_OPTION_KEYS`](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializable_resource.rb#L4).
|
||||||
The remaining options are serializer options.
|
The remaining options are serializer options.
|
||||||
|
|
||||||
Details:
|
Details:
|
||||||
@ -64,7 +64,7 @@ Details:
|
|||||||
1. **ActionController::Serialization**
|
1. **ActionController::Serialization**
|
||||||
1. `serializable_resource = ActiveModel::SerializableResource.new(resource, options)`
|
1. `serializable_resource = ActiveModel::SerializableResource.new(resource, options)`
|
||||||
1. `options` are partitioned into `adapter_opts` and everything else (`serializer_opts`).
|
1. `options` are partitioned into `adapter_opts` and everything else (`serializer_opts`).
|
||||||
The adapter options keys for the are defined by `ADAPTER_OPTIONS`.
|
The `adapter_opts` keys are defined in `ActiveModel::SerializableResource::ADAPTER_OPTION_KEYS`.
|
||||||
1. **ActiveModel::SerializableResource**
|
1. **ActiveModel::SerializableResource**
|
||||||
1. `if serializable_resource.serializer?` (there is a serializer for the resource, and an adapter is used.)
|
1. `if serializable_resource.serializer?` (there is a serializer for the resource, and an adapter is used.)
|
||||||
- Where `serializer?` is `use_adapter? && !!(serializer)`
|
- Where `serializer?` is `use_adapter? && !!(serializer)`
|
||||||
|
|||||||
@ -67,7 +67,7 @@ module ActiveModel
|
|||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
# Find a serializer from a class and caches the lookup.
|
# Find a serializer from a class and caches the lookup.
|
||||||
# Preferentially retuns:
|
# Preferentially returns:
|
||||||
# 1. class name appended with "Serializer"
|
# 1. class name appended with "Serializer"
|
||||||
# 2. try again with superclass, if present
|
# 2. try again with superclass, if present
|
||||||
# 3. nil
|
# 3. nil
|
||||||
|
|||||||
@ -23,5 +23,13 @@ module ActiveModel
|
|||||||
options = nil
|
options = nil
|
||||||
assert_equal @adapter.as_json(options), @serializable_resource.as_json(options)
|
assert_equal @adapter.as_json(options), @serializable_resource.as_json(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_use_adapter_with_adapter_option
|
||||||
|
assert ActiveModel::SerializableResource.new(@resource, { adapter: 'json' }).use_adapter?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_use_adapter_with_adapter_option_as_false
|
||||||
|
refute ActiveModel::SerializableResource.new(@resource, { adapter: false }).use_adapter?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user