* Really fix intermittent relationship test failures
* Unify the two JSON API relationship test files
I accidentally introduced the duplication when
merging
https://github.com/rails-api/active_model_serializers/pull/1543#issuecomment-193118782
and they've evolved separately since then.
They both have some value and need to be combined.
* Resolve duplicate tests from diverged tests files
* No longer test Association/Relationship interface directly
For JSONAPI, `include_data` currently means, "should we populate the
'data'" key for this relationship. Current options are true/false.
This adds the `:if_sideloaded` option. This means "only
populate the 'data' key when we are sideloading this relationship." This
is because 'data' is often only relevant to sideloading, and causes a
database hit.
Addresses https://github.com/rails-api/active_model_serializers/issues/1555
If you specify include_data false, and do not have any links for this
relationship, we would output something like:
`{ relationships: { comments: {} } }`
This is not valid jsonapi. We will now render
`{ relationships: { comments: { meta: {} } } }`
Instead.
Relevant jsonapi spec: http://jsonapi.org/format/#document-resource-object-relationships
* Make assocations asserts easier to understand
* Refactor Association into Field like everything else
* Make assocation serializer/links/meta lazier
* Push association deeper into relationship
* Simplify association usage in relationships
* Better naming of reflection parent serializer
* Easier to read association method
The `:attributes` adapter is the default one, but it did not support
key transformation. This was very surprising behavior, since the
"Configuration Options" page in the guides didn't mention that this
behavior was not supported by the attributes adapter.
This commit adds key transform support to the attributes adapter, and
adds documentation about the default transform for the attributes
adapter (which is `:unaltered`).
This commit also handles arrays when transforming keys, which was needed
in the case where you're serializing a collection with the Attributes
adapter. With the JSON adapter, it was always guaranteed to pass a hash
to the KeyTransform functions because of the top-level key. Since there
is no top-level key for the Attributes adapter, the return value could
be an array.
* replace reflection collection type with hash to prevent duplicated associations in some cases
* include tests
* Fix robucup offenses
* Improve test
* Remove usless requirement
* improve tests
* remove custom_options option from Post and InheritedPost serializer
* Improve tests
* update changelog
* update changelog
Fix code-styling issues from .rubocop_todo.yml
* re: RuboCop: Bulk minor style corrections
* re: RuboCop - hash indention corrections
* re: RuboCop - replace rocket style hashes
* re: RuboCop - get rid of redundant curly braces around a hash parameter
* re: RuboCop - Align the elements of a hash literal if they span more than one line.
* re: RuboCop - Use nested module/class definition instead of compact style.
* re: RuboCop - Suppress of handling LoadError for optional dependencies
* re: RuboCop - use include_ prefix instead of has_
* re: RuboCop - Disable Style/PredicateName rule for public API methods
* re: RuboCop - Remove empty .rubocop_todo.yml
* re: RuboCop - replace rocket style hashes
* Fix#1759, Grape integration, adds serialization_context
- `serialization_context` is added in grape formatter so grape continues to render models without an explicit call to the `render` helper method
- Made it straightforward for subclasses to add other serializer options (such as `serialization_scope`).
* Updated Grape tests to include:
- paginated collections
- implicit Grape serializer (i.e. without explicit invocation of `render` helper method)
* Update Changelog with fixes.
- improves improves serialization_context to take options and not depend
on a `request` object.
- adds descriptive error on missing serialization_context.
- Document overriding `CollectionSerializer#paginated?`.