NoMethodError is current_user is nil, so nil.admin?
NameError is a superclass of NoMethodError (which Rails 4.0 won't allow)
and means current_user might not be defined
- Setup dummy app files in `test/dummy`
- Setup dummy test server `bin/serve_dummy
- Note: Serializer caching can be completely disabled by passing in
`CACHE_ON=off bin/serve_dummy start` since Serializer#_cache is only
set at boot.
- run with
- ./bin/bench
- `bin/bench` etc adapted from ruby-bench-suite
- target files are `test/dummy/bm_*.rb`. Just add another to run it.
- benchmark cache/no cache
- remove rake dependency that loads unnecessary files
- remove git gem dependency
- Running over revisions to be added in subsequent PR
Adding a benchmak test structure to help contributors to keep track
of how their PR will impact overall performance.
It enables developers to create test inside of tests/benchmark.
This implementation adds a rake task: ```rake benchmark``` that checkout
one commit before, run the test of tests/benchmark, then mover back to
the last commit and run it again. By comparing the benchmark results between
both commits the contributor will notice if and how much his contribution
will impact overall performance.
- 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.
Fix the "Calling deprecated ArraySerializer... Please use
CollectionSerializer" warning that appeared when running the specs. This
happened because on of the test called ArraySerializer instead of
CollectionSerializer.
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.