mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 06:46:50 +00:00
add an example for how to test serializers easily
off topic: please deactivate the WIKI if there is no content in it
This commit is contained in:
parent
8ac4bf9006
commit
56eaa61233
11
README.md
11
README.md
@ -676,6 +676,17 @@ for the current user, the advantage of this approach is that, by setting
|
|||||||
`serialization_scope` to `nil`, the `index` action no longer will need to make
|
`serialization_scope` to `nil`, the `index` action no longer will need to make
|
||||||
that query, only the `show` action will.
|
that query, only the `show` action will.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
In order to test a Serializer, you can just call `.new` on it, passing the object to serialize:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
post = Post.first
|
||||||
|
serializer = PostSerializer.new post
|
||||||
|
serializer.to_json
|
||||||
|
# => "{\"post\":{\"id\":1...}}"
|
||||||
|
```
|
||||||
|
|
||||||
## Caching
|
## Caching
|
||||||
|
|
||||||
To cache a serializer, call `cached` and define a `cache_key` method:
|
To cache a serializer, call `cached` and define a `cache_key` method:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user