* 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
* 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
These errors are breaking the build, which seems to use RuboCop 0.40 [1]
despite the Gemfile.lock pinning rubocop to 0.38.
New lints that I am updating the code style to reflect:
- Style/EmptyCaseCondition: Do not use empty case condition, instead use
an if expression.
- Style/MultilineArrayBraceLayout: Closing array brace must be on the
same line as the last array element when opening brace is on the same
line as the first array element.
- Style/MultilineHashBraceLayout: Closing hash brace must be on the same
line as the last hash element when opening brace is on the same line
as the first hash element.
- Style/MultilineMethodCallBraceLayout: Closing method call brace must
be on the line after the last argument when opening brace is on a
separate line from the first argument.
[1] https://github.com/bbatsov/rubocop/releases/tag/v0.40.0
This is useful to set application-wide default behavior - e.g. in
previous versions of AMS the default behavior was to serialize the
full object graph by default - equivalent to the '**' include tree.
Currently just the global setting, but I think this could also work
on a per-serializer basis, with more attention.
This will prevent objects PORO objects that don't have updated_at defined, from throwing an error.
Not as big a deal now that PORO objects can inherit ActiveModelSerializers::Model, but still necessary if it's not inherited for whatever reason.
Add the Adapter type to the cache key.
This prevents incorrect results when the same object is serialized with different adapters.
BF:
Cherry-pick of
040a97b9e9
which was a squash of
f89ed71058
from pr 1346
- The removed classes and modules were added back with deprecation
warning and deprecation test were added for them.
- One test was renamed because it contained `__`.
- Some tests were refactored.
- The ActiveModelSerializers::Deserialization module is now called
Adapter instead of ActiveModelSerializers::Adapter.
- The changelog was added for #1535
Idea per remear (Ben Mills) in the slack:
https://amserializers.slack.com/archives/general/p1455140474000171
remear:
just so i understand, the adapter in `render json: resource, status: 422, adapter: 'json_api/error',
serializer: ActiveModel::Serializer::ErrorSerializer` is a different one than, say what i’ve
specified in a base serializer with `ActiveModel::Serializer.config.adapter = :json_api`. correct?
and a followup question of, why not same adapter but different serializer?
me:
With the way the code is written now, it might be possible to not require a special jsonapi adapter.
However, the behavior is pretty different from the jsonapi adapter.
this first draft of the PR had it automatically set the adapter if there were errors. since that
requires more discussion, I took a step back and made it explicit for this PR
If I were to re-use the json api adapter and remove the error one, it think the serializable hash
method would look like
```
def serializable_hash(options = nil)
return { errors: JsonApi::Error.collection_errors } if serializer.is_a?(ErrorsSerializer)
return { errors: JsonApi::Error.resource_errors(serializer) } if serializer.is_a?(ErrorSerializer)
options ||= {}
```
I suppose it could be something more duckish like
```
def serializable_hash(options = nil)
if serializer.errors? # object.errors.any? || object.any? {|o| o.errors.any? }
JsonApi::Error.new(serializer).serializable_hash
else
# etc
```
Changed the namespace in adapters and folder to active_model_serializers from active_model::serializer
Changed namespace of adapters in serializers and other folders
Moved adapter_for_test file to active_model_serializers folder and changed namespace of adapter inside the test file
Require ActiveSupport's string/inflections
We depend on string/inflections to define String#underscore.
Refactor JsonApi adapter to avoid redundant computations.
Update readme.md to link to v0.10.0.rc4
changed namespace of adapter folder testcases
Changed all namespaces of adapter under active_moder_serializers
Namespaced IncludeTree which is from serializer module, so needed to namespace it properly
Fixed wrong namsepacing of fieldset
namespace change in deserializer json_api
Fixed the namespace for collection serializer when used inside adapter, changed namespace for adapter to new namespace which I had forgotten previously
Modified logging test and adapter test cases to make the testcases pass
Changed the yardoc links,as old links are not taking to documentation pages,proper links for 0.10,0.9 and 0.8 in rubydoc
Rubocop errors are fixed by underscore naming unused variables
Moved the require of adapter to serializable resource
Remoeved adapter dependency inside serializer and added warning to Serializer::adapter method
Fixed frament cache test which is calling Serializer.adapter
Changed the name of lookup_adapter_from_config to configured_adapter
Changed the docs which will show the new namespace of adapters
Rubocop fix
The ActiveModel::Serializer.type method now accepts symbol as paremeter:
class AuthorSerializer < ActiveModel::Serializer
type :profile
end
The test file for the type was also refactored.
When using the relationship link with a block, calling "meta" without "href", e.g.
has_one :bio do
link :related do
meta id: 1
end
end
results in in a nil "href", e.g.
{ links: { posts: { related: { href: nil, meta: { id: 1 } } } } }.
According to JSONAPI, we should be able to use meta without href
(http://jsonapi.org/format/#document-links).
When using the relationships DSL with a block e.g.
has_one :bio do
link :self, "some_link"
end
the "data" field would be rendered with a nil value even though the bio
is not nil. This happened because the block return value was set to nil
but used as a value for the "data" field.
PR #1454 was merged with some missing fixes. All these fixes are
addressed by this commit:
- Rename ActiveModel::Serializer::Adapter::JsonApi::Association to
ActiveModel::Serializer::Adapter::JsonApi::Relationship
- Move ActiveModel::Serializer::Adapter:: JsonApi::Relationship and
ActiveModel::Serializer::Adapter::JsonApi::ResourceIdentifier to
ActiveModel::Serializer::Adapter::JsonApi::ApiObjects module
- Add unit test for
ActiveModel::Serializer::Adapter::JsonApi::Relationship
- Add unit test for
ActiveModel::Serializer::Adapter::JsonApi::ResourceIdentifier
We were not previously cloning the type setting into the dynamically
generated cached/non-cached serializers for a given fragment-cached
serializer. This led to the type generated for JsonApi having the wrong
value when fragment caching is enabled by adding either :except or :only
options to cache.
This pulls the type setting from the fragment-cached serializer forward
onto the dynamic caching classes so it is preserved in the output.
I noticed that fragment caching does not actually check if caching is
enabled as it seemingly should.
The way CachedSerializer#fragment_cached? worked previously would return
true even in an environment where caching was disabled as defined by
`ActiveModelSerializers.config.perform_caching`.
Added check for `_cache` like in the `cached?` method before checking
whether `_cache_only` or `_cache_except` is set.
There were no existing tests for any of these methods but it's a pretty
trivial change.